WooCommerce: Add a New Country For Billing/Shipping

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 CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @community     https://businessbloomer.com/club/

add_filter( 'woocommerce_countries', 'bbloomer_add_country' );

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

add_filter( 'woocommerce_continents', 'bbloomer_add_country_to_continent' );

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

add_filter( 'woocommerce_states', 'bbloomer_add_country_states' );

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

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Remaining $$$ to Get Free Shipping Notification @ Cart
    This is a very cool snippet that many of you should use to increase your average order value. Ecommerce customers who are near the “free shipping” threshold will try to add more products to the cart in order to qualify for free shipping. It’s pure psychology. So, here’s how we show a simple message on […]
  • WooCommerce: Cart and Checkout on the Same Page
    This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and checkout form on the same (Checkout) page. But first… why’d you want to do this? Well, if you sell high ticket products (i.e. on average, you sell no more than […]
  • WooCommerce: Disable Payment Method If Product Category @ Cart
    Today we take a look at the WooCommerce Checkout and specifically at how to disable a payment gateway (e.g. PayPal) if a specific product category is in the Cart. There are two tasks to code in this case: (1) based on all the products in the Cart, calculate the list of product categories in the […]
  • WooCommerce: Add Privacy Policy Checkbox @ Checkout
    Here’s a snippet regarding the checkout page. If you’ve been affected by GDPR, you will know you now need users to give you Privacy Policy consent. Or, you might need customer to acknowledge special shipping requirements for example. So, how do we display an additional tick box on the Checkout page (together with the existing […]
  • WooCommerce: Redirect to Custom Thank you Page
    How can you redirect customers to a beautifully looking, custom, thank you page? Thankfully you can add some PHP code to your functions.php or install a simple plugin and define a redirect to a custom WordPress page (as opposed to the default order-received endpoint). This is a great way for you to add specific up-sells, […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

8 thoughts on “WooCommerce: Add a New Country For Billing/Shipping

  1. HI,
    I don’t think your snippet for Custom country is working with the latest woocomerce, I’m using Version 8.2.1 and I’m getting the error MISSING_SHIPPING_ADDRESS The shipping address is required when `shipping_preference=SET_PROVIDED_ADDRESS`. when i use a custom country but it works fine on a standard woocommerce country. Could you have a look at your code please? Its very useful.

    1. Hiya Breda! Do you get that error on the Checkout page?

      1. Hi Rodolfo
        Yes on the checkout page, if you choose Northern Ireland and fill in all the required fields, click paypal and then the error shows at the top of the checkout page.

        1. Tried checking out with COD and got no error, so I believe this is something to do with the PayPal plugin you use. Which one is it?

          1. Hi! We have also encountered an error upon checking out. Seems like WooCommerce doesn’t acknowledge the newly added country code ‘XI’.

            “Country ‘XI’ is unknown. Try using a 2-character alphanumeric country code instead, such as ‘US’, ‘EG’, or ‘GB’.”

            1. Checked out with BACS to test and got no error. Can you tell me which payment method gave you the error – and if you try to pay with BACS do you get it?

              1. Got the error: Country ‘XI’ is unknown. Try using a 2-character alphanumeric country code instead, such as ‘US’, ‘EG’, or ‘GB’. A full list of country codes is available at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements

                normal woocommerce checkout with Stripe payment we got the above error.

                1. I guess the solution would be to revert to GB once the order is placed, so that whatever online payment gateway (Stripe in this case), gets the correct value (XI is not supported I guess). This could help: https://www.businessbloomer.com/woocommerce-update-checkout-field-value-after-order/

Questions? Feedback? Customization? Leave your comment now!

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *