Home » WooCommerce: Add a New Country For Billing/Shipping

WooCommerce: Add a New Country For Billing/Shipping

by Tutor Aspire

There are times when the WooCommerce countries database is simply not enough. While the WooCommerce team is usually very fast at updating its code (though, the newest country is apparently South Sudan, which became independent in 2011, the year WooCommerce launched!), you may need to DIY in certain cases.

Think of Northern Ireland for example. It’s not a “country”, however most Irish businesses would ship to Northern Ireland and not to “UK”, so having “Northern Ireland” in the Checkout page country dropdowns may help.

In this edge case study, we’ll basically take a look at how to add a custom country, how to make sure this custom country shows at checkout as a possible option (and in the shipping zones admin section), and also how to assign to it a custom list of states. You never know!

Northern Ireland is now in the list of WooCommerce Billing & Shipping countries, thanks to the snippet below!

PHP Snippet: Add a Custom Country @ WooCommerce Admin / Checkout

/**
 * @snippet       Custom Country @ WooCommerce Checkout
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_filter( 'woocommerce_countries', 'tutoraspire_add_country' );

function tutoraspire_add_country( $countries ) {
$new_country = array(
'XI' => 'Northern Ireland',
);
return array_merge( $countries, $new_country );
}

add_filter( 'woocommerce_continents', 'tutoraspire_add_country_to_continent' );

function tutoraspire_add_country_to_continent( $continents ) {
$continents['EU']['countries'][] = 'XI';
return $continents;
}

add_filter( 'woocommerce_states', 'tutoraspire_add_country_states' );

function tutoraspire_add_country_states( $states ) {
$states['XI'] = array(
'AN' => 'Antrim',
'AR' => 'Armagh',
'DY' => 'Derry',
'DO' => 'Down',
'FM' => 'Fermanagh',
'TR' => 'Tyrone',
);
return $states;
}

You may also like