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. Riaz Ejaz Avatar
    Riaz Ejaz

    There’s no file named as states.php in plugins folder. I want to set shipping price 200Rs for Karachi a city in Pakistan and 280Rs for other cities of Pakistan. Is it possible to do with this plugin please let me know thanks!

    Regards
    Riaz Ejaz

    1. Condless Avatar

      Dear Riaz,
      Select Pakistan via the plugin settings and press ‘Save Changes’, then create 1 shipping zone with flat rate shipping method (200Rs) and choose Karachi in the Zone regions field, and another shipping zone with flat rate shipping method (280Rs) and choose Pakistan in the Zone regions field, make sure the Karachi shipping zone is above the Pakistan shipping zone.

  2. Carlos Rosales Avatar

    Dear Sir
    Would it be possible to add El Salvador to the supported countries?

    1. Condless Avatar

      Hi Carlos, El Salvador was added to the supported countries

    2. Mauricio Avatar

      Thank you Condless! It works great. We are only missing one city “Santa Tecla”, could it be possible to add it?

    3. Condless Avatar

      Hi, Santa Tecla was added to the cities list

  3. Kun Avatar
    Kun

    Hi there,

    I’m a wordpress developer, working actually on a multiple pickup and shipping location e-shop. I have some questions about this awesome Cities Shipping Zone for WooCommerce :

    1. I have removed unnecessary cities in the French city list. In order to reduce load time.
    2. On the checkout and summary page our customers can only choose cities from the drop-down list, but we also have some customers from outside the zone come to us to pick up the order.
    3. So could you add for example « 0 – other cities » on the top of the drop-down list and when the customer choose this option the dropdown transform to text input for customers to enter the city name manually.

    I think this option could be done with a little more conditional logic (if…else), and lots of users need to this in order to make invoice with the right city name of users.

    Thank you for the reply and help.

    1. Condless Avatar

      Hi Kun, please see the ‘How to let the customer to select a city which is not displayed’ section in the docs, full instructions were sent to you by Email

    2. Kun Avatar
      Kun

      That’s work like a charm for me, thanks for the help.

    3. Kun Avatar
      Kun

      Oh other problem, this select dropdown should be applied to the cart shipping calculation sections too. Please help !

    4. Condless Avatar

      Hi, the code in the docs was updated to be applied on the cart shipping calculator as well

    5. Kun Avatar
      Kun

      Awesome ! Thanks for you help, this plugin is very useful and will be very popular !

  4. Jose Castillo Avatar

    Thanks! This is exactly what I’ve been looking for! How to change the form placeholder from ¨City¨ to ¨District¨? Exactly where I can change this?

    Thanks a lot.

    1. Condless Avatar

      Hi Jose, please try to add this into your theme’s functions.php file:
      add_filter( 'woocommerce_get_country_locale', 'csz_modify_city_label', 9999 );
      function csz_modify_city_label( $locale ) {
      $locale['PE']['state']['label'] = __( 'Distrito' );
      return $locale;
      }

  5. Michele Avatar
    Michele

    Hi, thanks for this plugin, it’s great.
    I have only one issue, in dropdown city list, either in cart and checkout page, it don’t find all cities in Varese province (all under ‘VA’ in IT.php).
    Thanks in advance.

    1. Condless Avatar

      Hi Michele,
      Can you give an example of city which is not present?
      Also make sure the ‘Filters’ option (via the plugin settings is not enabled)

    2. michele Avatar
      michele

      Hi, a customer reported me “Castelveccana” but also tryng with “Varese” doesn’t work, it seem that every city in the list of this province are not found.
      I’ve checked only “Autofill the state in orders based on the selected city “

    3. Condless Avatar

      Hi, please try to modify from ‘VA’ to ‘MI’ in line 1665 of the IT.php file

    4. Michele Avatar
      Michele

      It works!

    5. michele Avatar
      michele

      Can I leave it like this or will this change give some problems?

    6. Condless Avatar

      It’s totally okay to leave it that way

  6. michele Avatar
    michele

    Many thanks!

  7. Firdaus 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 “Malaysia” to the supported countries.

    Thank you in advance.

    1. Condless Avatar

      Hi Firdaus,
      Malaysia was added to the plugin

    2. Firdaus Avatar

      thank you very much bro….

  8. TINA Avatar
    TINA

    Hi, formidable the plugin
    Please how can i add city “Bingerville” to country “Cote d’ivoire”

    1. Condless Avatar

      Hi Tina,
      Bingerville is considered as part of Abidjan, you can use the code from the docs in order to split Abidjan into its sub-prefectures (Abobo, Yopougon and so)

  9. Sheneika Avatar
    Sheneika

    Hi, I am trying to use your plugin but it says Jamaica is unsupported could you help please.

    1. Condless Avatar

      Hi Sheneika, the support for Jamaica was added, please update the plugin

  10. Liberty Osaze Oyugboh Avatar
    Liberty Osaze Oyugboh

    Thank you so much for making this plugin

    I tried to use the given snippet to display only certain cities but it gives me an error when I try to add the PHP code to my child theme.
    is there something I am doing wrong?

    here is my code :
    add_filter( ‘csz_cities’, ‘csz_set_cities’ );
    function csz_set_cities( $states ) {
    $country = ‘NG’;
    $cities = [ ‘NGLASU’, ‘NGLASH, ‘NGLAOI’, ‘NGLAOJ’, ‘NGLAMU’, ‘NGLALM’, ‘NGLALI’, ‘NGLAKO’, ‘NGLAID’, ‘NGLAIJ’, ‘NGLAII’, ‘NGLAIL’, ‘NGLAEO’, ‘NGLAEP’, ‘NGLABA’, ‘NGLAAP’, ‘NGLAAO’, ‘NGLAAL’, ‘NGLAAI’, ‘NGLAAG’ ];
    $new_states = [];
    foreach ( $cities as $city ) {
    if ( isset( $states[ $country ][ $city ] ) ) {
    $new_states[ $city ] = $states[ $country ][ $city ];
    }
    }
    $states[ $country ] = $new_states;
    return $states;
    }

    thanks in advance

    1. Condless Avatar

      Hi Osaze,
      In order to display only certain cities you can select those cities inside some shipping zone (via WooCommerce shipping settings) and then enable the ‘Selling Locations’ option (via the Cities plugin settings)

  11. Mostafa Avatar
    Mostafa

    Hello, I’m Trying To fing Jeddah City in Suadi Arabia ..Can You add it please..Thank you

    1. Condless Avatar

      Hi Mostafa, it appears as ‘Jiddah’

  12. Justina Avatar

    Hello, I love your plugin and it is working for me but my only concern is how to integrate both the city and state as an option. For example, instead of totally eliminating New York in the options when choosing Bronx County, it shows New York as the State and Bronx as one of the cities in the dropdown lists.

    Please how to configure this? Thanks

    1. Condless Avatar

      Hi Justina, please enable the ‘Filters’ option (via the plugin settings)

  13. Toheeb Avatar
    Toheeb

    Hi, I would like to allow my website to support listing of States before I select my Cities. Kindly explain how to achieve this.

    Also, I discovered that the Cities enumerated for Nigerian State are actually Local Government Areas, while I would like those LGAs to be further broken down into Towns and districts within. I have created a list of these Towns and districts myself and would love to incorporate into your plugin.

    How do I achieve that?

    1. Condless Avatar

      Hi Toheeb, it will require some customization in order to replace the LGAs with cities, please contact us.

  14. Jonas Mensah Avatar
    Jonas Mensah

    Hello
    Thanks for this amazing plugin. Can we please have support for Ghana

    Thank you so much

    1. Condless Avatar

      Hi Jonas, the support for Ghana was just added.

  15. Toheeb Avatar
    Toheeb

    Hi, Once I select my Shipping destination from the list, the checkout does not auto refresh to display Shipping Rates options. Neither does it updates when Shipping destination is changed.

    What could be the Problem?

    1. Condless Avatar

      Hi, it may happen if you change the built-in cities list, further details were sent by Email

Leave a Reply to Daniela Cancel reply

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