Add The Code Snippet

  1. Open functions.php file in your theme’s root folder.

The easiest way to edit a theme file in WordPress is via the WordPress dashboard. After logging into the dashboard, click on the Appearance menu and then choose Theme Editor on the left sidebar.

Open Theme editor WooCommerce

In the window, you can see the template files and other documents from your active theme under Theme Files on the right side of the screen.

If you scroll down a bit, you can find the functions.php with a label Theme Functions. Click on functions.php to open it in the WordPress theme editor.

  1. Copy the code snippet given below and paste.

Place it at the bottom of the functions.php file just before the closing PHP tag if there is one.

* Rename a country
add_filter( 'woocommerce_countries', 'rename_ireland' );
function rename_ireland( $countries ) {
$countries['IE'] = 'Ireland';
return $countries;

Explanation of the code

If you are not familiar with PHP or WordPress code, the code may look intimidating but it’s simple once you understand what each line of code does.

The first three lines of the code block are PHP comments.

rename country WooCommerce snippet

The fourth line binds a new custom function that we will define at the bottom to woocommerce_countries filter hook. In this code, the name of the new custom function is rename_ireland.

WooCommerce Country Rename Snippet

The code block from 6th to 9th lines defines the custom function that we want to bind to the woocommerce_countries filter hook. You can see that the name of the function in the 6th line and the second parameter for the add_filter function are the same.

Edit country name woocommerce

In the 7th line, the name of Ireland is changed from its original value to Ireland. So, this is the line of code you need to change if you want to rename a county in WooCommerce.

Woocommerce country name snippet

  1. Rename the function to a name that helps you remember it’s purpose.

For example, if you are changing the country name of the US, you can rename the function as rename_us or rename_united_states.

Please remember that you need to change the function name at both places: where you call the function and where you define the function. Otherwise, it won’t work.

rename country function woocommerce

  1. Replace the alpha 2 country code with the code of the country of which you want to change the name.

If you don’t know the Alpha-2 code of the countries as used in WooCommerce, you can refer to Table 1 given below.

    1. Enter the desired name inside the single quotes after the equal sign on the 7th line.

This will be displayed on your website.

  1. Save and close functions.php file and you are set to go.

Table 1

Want to experience what trusted eCommerce support feels like? Contact us now