Cities Shipping Zones for WooCommerce

Install the plugin to add country’s cities list that will be used as shipping zones.

Cities List

How to modify cities names?
Update country, cities codes, and cities names:

add_filter( 'woocommerce_states', 'csz_modify_woocommerce_states', 40 );
function csz_modify_woocommerce_states( $states ) {
	$country = 'AT';
	$states[ $country ]['AT90001'] = 'Vienna';
	return $states;

How to remove some cities from the list?
Update the code of the cities for removal:

add_filter( 'woocommerce_states', 'csz_remove_woocommerce_states', 50 );
function csz_remove_woocommerce_states( $states ) {
	$unnecessary_cities = array( 'AT10101', 'AT10201', 'AT10301' );
	foreach ( $unnecessary_cities as $city ) {
		unset( $states[ substr( $city, 0, 2 ) ][ $city ] );
	return $states;

How to keep only specific cities in the list?
Update the country and cities codes:

add_filter( 'woocommerce_states', 'csz_set_woocommerce_states', 20 );
function csz_set_woocommerce_states( $states ) {
	$country = 'AT';
	$cities = array( 'AT10101', 'AT10201', 'AT10301' );
	$new_states = array();
	foreach ( $cities as $city ) {
		if ( isset( $states[ $country ][ $city ] ) ) {
			$new_states[ $city ] = $states[ $country ][ $city ];
	$states[ $country ] = $new_states;
	return $states;

How to create shipping zones for areas inside a city?
Use zipcode, or split the city into sub-city areas which is less recommended (update country, cities codes, cities names):

add_filter( 'woocommerce_states', 'csz_split_woocommerce_states', 30 );
function csz_split_woocommerce_states( $states ) {
	unset( $states['AT']['AT90001'] );
	$states['AT'] += array(
		'AT900011' => 'Wien' . '- ' . __( 'Northern', 'woocommerce' ),
		'AT900012' => 'Wien' . '- ' . __( 'Southern', 'woocommerce' ),
	return $states;

How to create cities list for a unsupported country?
By its Local Census/UNLOCODE/HASC geocoded administrative divisions, city name must be unique.

How to bulk edit the cities of certain shipping zone?
Use the Bulk Edit option, if the variable $country_states exist in the cities list file you may use states as well, pay attention to not write the same city twice.

Which additional uses shop owners make with the customer city?
Displaying certain products (filter by city category), selling certain products (plugin that limits by state), shipping certain products (associating the products to a class without price in the relevant shipping method), applying taxes (using the city code in the state field in the settings), enabling payment / shipping methods (conditional payment / shipping plugin).

Distance Fee

Given a (domestic) city’s distances list, will be possible to add distance based fee for the shipping rate or product price (for example- to sell moving services). Israel have few cities with built-in cities distances list.

How to set the Distance Fee?
WooCommerce Settings: Verify the store location is set for a country with distances list, Plugin Settings: set the distance fee, Shipping Method Settings: set price and enable the distance fee.

Why I can’t see the distance fee in the Checkout?
Resave any shipping method (in order to flush the cache).

How I shall organize the distances list for some city?
Use as index the locations codes or names (as they appear in the website), verify to set distance to the city itself.

How to enter all the locations that distance is configured for them from a specific city?
In the Bulk Edit option, enter the character ‘!’ followed by the city code (currently it doesn’t support distances list indexed not by the website language.

  • Remove the locations from WooCommerce Shipping Zones settings.
  • Deactivate and delete the plugin.
  • Update the store location in WooCommerce settings.
  • Consider to convert/erase the state field values of orders and users that were created/updated while the plugin was applied on the countries they belong to.

Leave a Reply

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