How to add Gozo as a new Country in WooCommerce

During one of our latest e-commerce projects that we were developing for a client, we needed to implement different shipping options to account for the different pricing structures between shipping to Malta and Gozo.

It is a common request of course since the delivery fees for the business owners will vary, and in many cases, there will also be some operational differences as well. Therefore, since this is a very common requirement and there seem to be no easy guides on how to add this, we have decided to share the knowledge.

Step 1 – Install Code Snippets

From within your WordPress dashboard, click on Plugins > Add New

Search for “Code Snippets” and click on install.

Once Installed, you will need to click the blue Activate button.

Step 2 – Add the code

Don’t be alarmed, It’s gonna be super simple, promise. Once again, from your WordPress dashboard, navigate down to Snippets > Add New

On the next screen, you just need to add the details shown below, and press Save Changes and Activate. You do not need to write the code below manually, scroll below the image to find the code you can simply copy-paste.

Once saved, you will need to go back to “All snippets” and activate the code snippet that you have just created.

				
					/**
 * @snippet       Add Gozo to Woocommerce 
 * @author        Jesmond Darmanin - Storm Design https://storm-design.net

 */
 
add_filter( 'woocommerce_countries',  'stormdesign_add_my_country' );
function stormdesign_add_my_country( $countries ) {
  $new_countries = array(
	                    'GZ'  => __( 'Gozo', 'woocommerce' ),
	                    );

	return array_merge( $countries, $new_countries );
}

add_filter( 'woocommerce_continents', 'stormdesign_add_my_country_to_continents' );
function stormdesign_add_my_country_to_continents( $continents ) {
	$continents['EU']['countries'][] = 'GZ';
	return $continents;
}
				
			

And that’s it – you are done!