WooCommerce is a great solution for online shops but has its limitations. Shipping based on shipping zones and postcodes works well in most countries. But what if a country doesn’t have postcodes? In this article, you will learn how to add a United Arab Emirates city in WooCommerce.
The United Arab Emirates has no system of postal codes. Instead, they use registered PO Boxes, which are assigned individually. Other Gulf and Middle East countries also follow the same system. Shipping in WooCommerce is mainly based on postcodes, so shipping to individual cities in the UAE can be very problematic. Yes, in WooCommerce there is an option to choose the United Arab Emirates as a separate shipping zone. But what if the cost of shipping is different for different regions or cities? The best option is to add them yourself.
How to add a United Arab Emirates city in WooCommerce?
This is not about interfering with the WooCommerce code. The only thing that’s WooCommerce included is Countries and states/provinces for some countries. So we will use states to add cities. Especially since WooCommerce provides a filter named
woocommerce_states that we can use.
All you have to do is to add a special code in the theme’s functions.php file or use an additional plugin like Code Snippets. Here’s an example code, which I will cover in detail.
Basically, that code adds new states to WooCommerce. In my example, these are the biggest cities in the United Arab Emirates. You can also add new cities, just by adding new states. If you want to add Al Ain, just add a
'AA' => __( 'Al Ain', 'woocommerce' ) inside $states array.
How does it work?
It will add new states to the United Arab Emirates. This way, if you’ll go to WooCommerce > Settings > Shipping and add a new Shipping Zone, you will be able to select cities as a shipping zone.
The same will happen for your clients. On the checkout page or shopping cart, they will be able to select United Arab Emirates cities in the State / County dropdown field.
Examples of usage
WooCommerce shipping to Dubai
If you want to offer shipping to only one city, like Dubai, you can add a Shipping Zone restricted to only that one city.
Different shipping cost for each city
If you want to offer different shipping fees for each city, you can do it in two ways. First, you can add a separate shipping zone for each city and add a shipping method with a different fee inside all the zones. The second and much more convenient way is to use the Flexible Shipping Locations Add-on. It will allow you to configure it all in one shipping method.