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.

264 responses to “Cities Shipping Zones for WooCommerce”

  1. Samba Avatar

    Hello. The main cities of Senegal are not displayed in the plugin. There are only neighbourhoods in the zones. Can you help me by adding the regions this time? Please

    1. Condless Avatar

      Hi Samba,
      The cities list was taken from https://en.wikipedia.org/wiki/Arrondissements_of_Senegal
      Which cities are missing?

    2. Samba Avatar

      You only put the municipalities but not the cities or regions. For example you did’nt put Dakar and its departments …

    3. Condless Avatar

      It will require some customization in order to replace the municipalities with the cities/departments, please contact us.

  2. George Avatar
    George

    Hello champion, when do you it will be possible to add Rwanda?

    1. Condless Avatar

      Hi George, Rwanda was added to the plugin

    2. George Avatar
      George

      Thank you for the update. Long live this project!

  3. Ibas Avatar
    Ibas

    Hello, Good Plugin. Though, there are some cities missing under the Zone region. Please can we expand the list ourselves? If yes, in what files should we do this? Also, can we allow the customer to select a city which is not displayed?

    Thank you.

    1. Condless Avatar

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

    2. Ibas Avatar
      Ibas

      Please is it possible to set a flat rate to the rest of states within a country. Mind you, I have set the shipping rate for cities in the state the store is located. This takes a lot of time. Now, I want to set a fixed rate for the rest of the state. Please I don’t want to start selecting the cities one after the other. Thank you.

    3. Condless Avatar

      Hi, you can create another shipping zone and select ‘Nigeria’ in the Zone regions field, it will apply on all the cities which were not selected in the other shipping zone. Make sure that the cities shipping zones is appear above the country shipping zone.

  4. Jad Avatar
    Jad

    My store only delivers in Canada. I want the Free shipping method in 4 cities there which are as follows:
    Cobourg
    Port Hope
    Grafton
    Baltimore

    In all other Cities of Canada, I want Flat rate shipping of $15.

    Can I or how do I set this up?

    1. Condless Avatar

      Hi Jad,
      You can create shipping zone and select in the Zone regions field: Cobourg, Port Hope, Hamilton (which Baltimore is part of), Alnwick/Haldimand (which Grafton is part of) and add the free shipping method to it.
      Create another shipping zone and select ‘Canada’ in the Zone regions field and add the flat rate shipping method.
      Make sure the cities shipping zone appears above the Canada shipping zone.

    2. Jad Avatar
      Jad

      Thank you so much for taking the time to reply. When I type the name of any of those cities in the Zone Regions field, it does not come up and says no matches found. Please view the screenshot here https://ibb.co/gy21bzf

    3. Condless Avatar

      Please go to the Cities Shipping Zones tab, select Canada and press Save Changes

  5. Jad Avatar
    Jad

    Awesome. That worked. In the Cart Totals, it says shipping to CAHAMILTON or CACOBOURG. Can I do some modification to display the names without CA. By default, it said shipping to MB. How do I fix that too.
    https://ibb.co/gy21bzf

    1. Condless Avatar

      Please try to put the code from the ‘How to fix the display of the address in the shipping calculator?’ section into your theme’s functions.php

  6. XappA Avatar
    XappA

    Hi,

    I wanted to try this plugin as it looks promising but I am new to eCommerce and I just want to know if you have a step by step guide on how to use this for beginners. Setting this plugin and what needs to be done on the woocommerce part.

    Thanks

    1. Condless Avatar

      Hi,
      In the plugin settings (Dashboard => WooCommerce => Settings => Cities Shipping Zones) select your country in the first field and press the ‘Save Changes’ button.
      In WooCommerce shipping settings (Dashboard => WooCommerce => Settings => Shipping) edit/create a shipping zone, select some cities in the ‘Zone regions’ field, and add to it a shipping method with the desired price for the cities you have selected.

  7. XappA Avatar
    XappA

    Another question, I dont see Etobicoke as a city in Canada, How do I add it?

    1. Condless Avatar

      Etobicoke is considered as part of Toronto, you can use postcodes restrictions to assign it different shipping rate.

  8. XappA Avatar
    XappA

    I added that and restricted via specific post code but its not showing on the drop-down list

    1. Condless Avatar

      People from Etobicoke should select Toronto in the city field and can write Etobicoke in the address field. Although it’s possible to modify the name of one of the other cities into ‘Etobicoke’ it’s not recommended.

  9. Cesar Peralta Avatar

    Hello, I am using the plugin for PerĂº but is missing one department (Piura) and in Lima a city called “magdalena vieja” is now “pueblo libre”.
    How can I add or modify the cities names?

    1. Condless Avatar

      Hi Cesar,
      Please redownload the plugin, set your store address (WooCommerce General settings), and add this into your theme’s functions.php file:
      add_filter( 'csz_cities', 'csz_modify_cities' );
      function csz_modify_cities( $cities ) {
      $country = 'PE';
      $city = 'PE150121';
      if ( isset( $cities[ $country ][ $city ] ) ) {
      $cities[ $country ][ $city ] .= ' (Pueblo Libre)';
      }
      return $cities;
      }

    2. Cesar Peralta Avatar

      Thanks for you reply, so first i have to uninstall the plugin and install again?

    3. Condless Avatar

      Yes, exactly

  10. Riadh Avatar
    Riadh

    Hi there,
    Thank you for this great plugin, it works great! However, when activated, everything works well and the order is created in backend but the checkout page stays on loop. Any idea what that might be ? I’m using Rey Theme

    1. Condless Avatar

      Hi Riadh,
      Please make sure the address of your store is set properly (Dashboard => WooCommerce => Settings => General), what’s the URL of the checkout page?

    2. Riadh Avatar
      Riadh

      My address is set properly, I don’t see any changes I can make. Please help

    3. Riadh Avatar
      Riadh

      Sorry, my bad. It’s frustrating, haha!

    4. Condless Avatar

      Can you try temproraly to switch to another theme? The issue occures only when the plugin is active?

    5. Riadh Avatar
      Riadh

      I asked the theme developer the same question, since I’m still on support. I’ll try disabling the theme and see what happens. I might mention I added some cities in the i18n plugin folder by copy pasting and changing the last digit. Is it what’s causing this to happen ? Do I need to add them like you mentioned in this page in order for the plugin to work ?

    6. Condless Avatar

      Changing the cities file directly can cause issues, try backup your edits and redownload the plugin (it will override your edits).

    7. Riadh Rebei Avatar
      Riadh Rebei

      Hello back, I fixed the issue. It was mainly a server problem and your plugin had nothing to do with that, haha. However, I have a question : Can I display the regions dropdown other than Alphabetically ? And please delete the comments with my staging website on them. Thank you

    8. Condless Avatar

      You can redownload the plugin and use the code from the docs:
      “How to move some states to the top of the dropdown?”
      Update the keys in $first_keys var, for example:
      $first_keys = [ ‘MA07’, ‘MA09’, ‘MA04’ ];

  11. Junaid Khan Avatar

    Hey I would like to replace the municipalities with the cities for Pakistan country. Can you please help me with that? I have a list of cities and states updated and I would like to add that list to the plugin. Can you let me know if I can use a custom file for a country just for my website? Adding a whole list and removing the other cities from the plugin individually would take a lot of time. I need help regarding this.

    1. David Chukwu Avatar
      David Chukwu

      You can modify your cities or municipalities by accessing this folder

      \wp-content\plugins\cities-shipping-zones-for-woocommerce\i18n\cities
      Open your country php file eg DE.php for Germany, modify the content and save it

  12. David Chukwu Avatar

    Hello how can I integrate other shipping options (eg UPS, DHL) to handle shipping method to other countries (International Shipping)
    Because creating shipping price for each city in the world is cumbersome

    1. Condless Avatar

      Hi David,
      You can select the countries in the ‘Zone regions’ field of the shipping zone which contains those shipping methods.

  13. Shaker Avatar
    Shaker

    after installing the plugin every thing is fine. BUT the “add to cart” and quantity increase decrease in product single page stop working.
    do you have any idea?!

    1. Condless Avatar

      Hi Shaker,
      Is the situation back to normal when deactivating the plugin? can you share the product page URL?

  14. Tala Avatar
    Tala

    Hello, Thank you for your support
    Can you add Oman And Bahrain to the supported countries?

    1. Condless Avatar

      Hi Tala,
      It will require customization, please contact us.

  15. Shubham Avatar
    Shubham

    How can i get any demo website link

    1. Condless Avatar

      Hi Shubham,
      It was sent to you by Email.

Leave a Reply

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