Cities Shipping Zones for WooCommerce

How to set different shipping rates per city?
In the plugin settings choose on which countries to apply the plugin on, create new shipping zone and add the cities inside, add the relevant shipping methods and prices.

How to apply taxes per city/state?
In WooCommerce tax settings use the city code at the state field, or use the city code at the city field and the state code at the state field and add:

add_filter( 'csz_enable_tax_per_state', '__return_true' );

How to convert cities list (cities seperated by lines) to the Bulk Select tool required format (cities seperated by ;)?
Replace [\r\n]+ (regex) with ; in Notepad++.

How to retrieve the shipping zone / the state that some city is belong to from a 3-party app?
Extension for the WooCommerce REST API is available.

How to translate cities names?
Use the built-in WordPress editor, filter your country’s cities using {country_code}-cities (for example use EE-cities for Estonia, contact us if the cities are absent or if you have ready-made translation), when finish translating contact your language team to approve it, then export the .mo file to your /wp-content/languages/plugins/ folder and change its name to cities-shipping-zones-for-woocommerce-{language_code}.

How to modify cities names?
Update countries codes, and cities codes and names (add the state prefix if using the ‘State Filters’ option):

add_filter( 'csz_cities', 'csz_modify_cities_names' );
function csz_modify_cities_names( $cities ) {
	$country = 'EE';
	$cities_names = [
		'EE784'	=> 'Talin',
		'EE296'	=> 'Keilalinn',
	];
	foreach ( $cities_names as $key => $city ) {
		if ( isset( $cities[ $country ][ $key ] ) ) {
			$cities[ $country ][ $key ] = $city;
		}
	}
	return $cities;
}

How to remove some cities from the list?
Update country code and cities codes:

add_filter( 'csz_cities', 'csz_remove_cities' );
function csz_remove_cities( $cities ) {
	$country_code = 'EE';
	$unnecessary_cities = [ 'EE784', 'EE296', 'EE446' ];
	foreach ( $unnecessary_cities as $city ) {
		if ( isset( $cities[ $country_code ][ $city ] ) ) {
			unset( $cities[ $country_code ][ $city ] );
		}
	}
	return $cities;
}

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

add_filter( 'csz_cities', 'csz_set_cities' );
function csz_set_cities( $cities ) {
	$country = 'EE';
	$keep_cities = [ 'EE784', 'EE296', 'EE446' ];
	foreach ( $keep_cities as $city ) {
		if ( isset( $cities[ $country ][ $city ] ) ) {
			$new_cities[ $city ] = $cities[ $country ][ $city ];
		}
	}
	if ( ! empty( $new_cities ) ) {
		$cities[ $country ] = $new_cities;
	}
	return $cities;
}

How to remove from the list all the cities of certain states?
Update states codes:

add_filter( 'csz_states', 'csz_remove_states_cities' );
function csz_remove_states_cities( $states ) {
	$unnecessary_states = [ 'EE001', 'EE004', 'EE006' ];
	foreach ( $unnecessary_states as $state_code ) {
		if ( isset( $states[ $state_code ] ) ) {
			unset( $states[ $state_code ] );
		}
	}
	return $states;
}

How to keep in the cities dropdown only the cities from certain states (not compatible with international stores)?
Update states codes:

add_filter( 'csz_states', 'csz_set_states' );
function csz_set_states( $states ) {
	$keep_states = [ 'EE001', 'EE004', 'EE006' ];
	foreach ( $keep_states as $state ) {
		if ( isset( $states[ $state ] ) ) {
			$new_states[ $state ] = $states[ $state ];
		}
	}
	return $new_states ?? $states;
}

How to create shipping zones for quarters inside a city?
Create shipping zone with that city and restrict to the relevant postcodes or add multiple flat rate shipping methods to the shipping zone for the different areas, or split the city into areas (less recommended, update country code and city code and areas names, update the store location in WooCommerce settings, not compatible with the ‘State Autofill’ option):

add_filter( 'csz_cities', 'csz_split_cities' );
function csz_split_cities( $cities ) {
	$country_code = 'EE';
	$city_code = 'EE784';
	$sub_cities = [ __( 'Northern', 'woocommerce' ), __( 'Southern', 'woocommerce' ) ];
	if ( isset( $cities[ $country_code ][ $city_code ] ) ) {
		$count = 101;
		foreach ( $sub_cities as $sub_city ) {
			$cities[ $country_code ][ $city_code . $count ] = $cities[ $country_code ][ $city_code ] . ' - ' . $sub_city;
			$count++;
		}
		unset( $cities[ $country_code ][ $city_code ] );
	}
	return $cities;
}

How to group multiple cities into one area?
Update the country code, the area name (add the state prefix if using the ‘State Filters’ option) and its main city, and the cities its included:

add_filter( 'csz_cities', 'csz_group_cities' );
function csz_group_cities( $cities ) {
	$country_code = 'EE';
	$area_name = 'Tallinn Area';
	$main_city_code = 'EE784';
	$secondary_cities = [ 'EE296', 'EE446', 'EE726', 'EE890' ];
	if ( isset( $cities[ $country_code ][ $main_city_code ] ) ) {
		foreach ( $secondary_cities as $city ) {
			if ( isset( $cities[ $country_code ][ $city ] ) ) {
				unset( $cities[ $country_code ][ $city ] );
			}
		}
		$cities[ $country_code ][ $main_city_code ] = $area_name;
	}
	return $cities;
}

How to move some cities to the top of the dropdown?
Update the country and cities codes:

add_filter( 'csz_cities', 'csz_cities_custom_order' );
add_filter( 'csz_sort_cities', 'csz_disable_sort', 10, 2 );

function csz_cities_custom_order( $cities ) {
	$country = 'EE';
	$first_keys = [ 'EE726', 'EE890' ];
	$pre_arr = [];
	foreach ( $first_keys as $key ) {
		if ( isset( $cities[ $country ][ $key ] ) ) {
			$pre_arr[ $key ] = $cities[ $country ][ $key ];
		}
	}
	asort( $cities[ $country ] );
	$cities[ $country ] = $pre_arr + $cities[ $country ];
	return $cities;
}

function csz_disable_sort( $sort, $country_code ) {
	$country = 'EE';
	return $country === $country_code ? false : $sort;
}

How to move some states to the top of the dropdown?
Update the states codes:

add_filter( 'csz_sort_states', '__return_false' );
add_filter( 'csz_states', 'csz_states_custom_order' );
function csz_states_custom_order( $states ) {
	$first_keys = [ 'EE007', 'EE004' ];
	$pre_arr = [];
	foreach ( $first_keys as $key ) {
		if ( isset( $states[ $key ] ) ) {
			$pre_arr[ $key ] = $states[ $key ];
		}
	}
	asort( $states );
	return $pre_arr + $states;
}

How to let customers to select a city which is not exist in the list?
Shipping zone for the countries you applied the plugin on must be configured or at ‘Locations not covered’ if ‘Selling locations’ option is enabled (not compatible with the ‘State Filters’ and ‘State Autofill’ options):

add_filter( 'csz_enable_custom_city', '__return_true' );

How to uninstall the plugin?
WooCommerce Shipping Zones settings: erase the locations.
Plugin Settings: Remove the countries.
WooCommerce General Settings: Update the store location country / state.
Users: convert/erase the state field values of users that were created/updated while the plugin was applied on the countries they belong to.
Plugins: Deactivate and delete the plugin.

275 responses to “Cities Shipping Zones for WooCommerce”

  1. Hindal Avatar
    Hindal

    Hi,

    I was trying to use your “Cities Shipping Zones for WooCommerce” plugin. However, the country I am trying to use this plugin is not supported. I would to request to add “United Arab Emirates” to the supported countries.

    Thank you in advance.

    1. Condless Avatar

      Hi Hindal, support for the United Arab Emirates was added.

    2. Luraif Hassen Avatar

      Cities Shipping Zones for WooCommerce (Plugin)

      Hi,
      i installed this plugin through wordpress dashboard After installed this plugin my site is down error code is 503 service unavailable.
      can’t access wordpress Dashboard also.
      I removed plugin through C-panel after okay My site.

      i am interesting to use this plugin to my site (all cities include in Sri Lanka)

      * WordPress version is 5.8.2
      * X-store Theme version is 8.0.11

      I will be hope, Given solutions for this issues

      BR.
      Luraif Hassen

  2. Mohamad Avatar
    Mohamad

    can you please add JORDAN to the supported countries, or let me know please how i can add it
    Thanks

    1. Condless Avatar

      Hi Mohamad, Jordan was added to the supported countries.

  3. Ganji Madhukar Avatar

    Hi,

    I was trying to use your “Cities Shipping Zones for WooCommerce” plugin. However, India is not working

    1. Condless Avatar

      Dear Ganji, in the latest plugin version India is supported.

  4. Raditya Avatar
    Raditya

    Hello,
    Do you mind to add Indonesia to the supported countries?

    Thanks a lot!

    1. Condless Avatar

      Raditya, Indonesia is supported but the address format in Indonesia contains states, so if you use the plugin you will not able to integrate your website with online payment or shipping software.

    2. Raditya Avatar
      Raditya

      That’s a bummer! Guess I’ll have to add them by zip codes, which is a lot of work to do. Thanks for the fast reply and wish you have a great day!

    3. Condless Avatar

      Hi, in the latest plugin update the ‘autofill state’ option was added, when enabled the integration with online payment and shipping software should function as usual.

  5. gg dd Avatar
    gg dd

    Dear, please help on following
    1. could you please add Myanmar as a supported country
    2. how to add different cities in Myanmar, where shipping zone applies as customer enters the city at check out page.

    Thank you

    1. Condless Avatar

      Myanmar will be added in the next release. Once its added, you will be able to select cities in the Shipping Zones edit screen (Dashboard => WooCommerce => Settings => Shipping)

  6. Seyi Gbadamosi Avatar

    Hi could you please add Nigeria to your list of supported countries

    1. Condless Avatar

      Hi Seyi, Nigeria is supported

    2. obinna obidike Avatar

      Hello Seyi,
      If you achieved shipping costs by cities(wuse, gwarinpa, asokoro).
      Please how did you do it?
      Still finding it tough achieving it.

      Thanks in advance.

  7. Marco Avatar
    Marco

    Excellent complement!
    Congratulations

    I have seen “How to modify cities names?”, it could be a solution but I don’t know what the city codes of my country / state are

    Can I just add a city?
    Where can I get the country / city codes to modify them?

    Thanks!

    1. Condless Avatar

      Hi,
      The states/cities codes list is inside the plugin folder in the path:
      /cities-shipping-zones-for-woocommerce/i18n/cities/

  8. Kevin Avatar

    Hi,
    Hi could you please add Bolivia to your list of supported countries
    In my country we don’t have postal codes..

    1. Condless Avatar

      Hi Kevin, support for Bolivia will be available in the next plugin update.

    2. Kevin Avatar

      Thank you very much, this is a great complement!!

  9. hassan el bouatmani Avatar

    Hi,

    I was trying to use your “Cities Shipping Zones for WooCommerce” plugin. However, the country I am trying to use this plugin is not supported. I would to request to add “Morocco” to the supported countries.

    Thank you in advance.

    1. Condless Avatar

      Dear Hassan,
      Morocco is supported by the plugin

  10. Krishneel Avatar
    Krishneel

    Hi, can you please add support for Fiji

    1. Condless Avatar

      Hi Krishneel, Fiji is better organized by its provinces so no need to use the plugin just add this to your theme’s functions.php file:
      add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
      function custom_woocommerce_states( $states ) {
      $states['FJ'] = [
      'FJ01' => 'Ba',
      'FJ02' => 'Bua',
      'FJ03' => 'Cakaudrove',
      'FJ04' => 'Kadavu',
      'FJ05' => 'Lau',
      'FJ06' => 'Lomaiviti',
      'FJ07' => 'Macuata',
      'FJ08' => 'Nadroga and Navosa',
      'FJ09' => 'Naitasiri',
      'FJ10' => 'Namosi',
      'FJ11' => 'Ra',
      'FJ12' => 'Rewa',
      'FJ13' => 'Serua',
      'FJ14' => 'Tailevu',
      ];
      return $states;
      }

  11. La Avatar
    La

    I am trying to add Sri Lanka but it issems this is not working for Sri Lanka

    1. Condless Avatar

      Hi, make sure Sri Lanka was selected in the plugin settings ‘Country / Region’ field (‘The countries to apply the plugin on’), in WooCommerce Shipping Settings click edit on the first shipping zone and insert some cities of Sri Lanka in its ‘Zone regions’ field.

    2. gunasena Avatar
      gunasena

      Some Cities are not listed for Srilanka How to add it?
      I hope you can make some coding to add the missing cities in the Backend

      At now Please help me to add some city names
      And for feature updates Kindly Refer the city names in daraz.lk

    3. Condless Avatar

      Hi,
      Which cities are missing? you can redownload the plugin in order to have the latest cities list of Sri Lanka.

  12. obinna obidike Avatar

    Hi, Thank you for the plugin.
    1. Please can you add NIGERIA.
    2. I added a shipping zone, it showed “Unsupported: Asokoro”

    Thanks

    1. Condless Avatar

      Hi Obinna, After you have selected Nigeria via the plugin settings, go to shipping zone edit screen (Dashboard => WooCommerce => Settings => Shipping) and select the cities in the Zone regions field.

  13. SGE Avatar
    SGE

    I’m having some issues while integrating with cybersource, and I need to be able to set the “state” to the same as “country” (as cybersoruce support indicated) so, can you please help me to achieve this?

    1. Condless Avatar

      Hi, can you provide more details? the state field is filled only if the ‘State Autofill’ option is enbaled, do they ask that for the US or for other countries? Does it work when the plugin is disabled?

  14. Esmee Avatar
    Esmee

    Hello,
    Would love to use this for my site. But it does not show every city in the Netherlands. How is this possible?

  15. Florent Avatar
    Florent

    Can you please add “Kosovo” to the supported countries!

    1. Condless Avatar

      Hi Florent, it was just added

Leave a Reply

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