How to process WooCommerce Shipping for Countries with no ZIP code? (Code Snippet)

There are many countries that don’t have states or an official postal code. The WooCommerce cart’s shipping calculator only provides Country, State, and Postal code field by default. While the recent versions of WooCommerce show the city name field when a country with no postal code is selected, some of the older versions do not show the city name field, hence making difficult for customers to check out.

Some of the WooCommerce versions make the postal code mandatory, so how would you calculate shipping for the countries that don’t have a postal code?

ELEX has a simple, effective solution to provide a text field for accepting city names when the selected country does not have a postal code. This city text field can be added to your WooCommerce cart, by using our City for country plugin. You can download the free plugin and install on your WordPress site.

A new field accepting city names will appear in your WooCommerce cart page, as shown in the screenshot below.

Once the plugin is installed, your WooCommerce cart should be ready to accept city names for processing the shipments.

For this, you need to add the following code snippet in the functions.php file of your currently activated theme.