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.

271 responses to “Cities Shipping Zones for WooCommerce”

  1. nizlan Avatar

    how can I bulk select all cities for rates

    1. Condless Avatar

      Hi Nizlan,
      If you need all the cities you can choose the country itself in the shipping zone, otherwise you can use the Bulk Select tool (via the plugin settings) which allow you to bulk insert by states or cities.

    2. Angel Sarat Avatar
      Angel Sarat

      did you solved the problem, cause this plugin is really good in order to customize the cities into a country that are not recognized by WC

    3. Condless Avatar

      Hi Angel,
      What problem did you encounter?

  2. Faizan Avatar

    Hi,

    Please guide me how to add some cities names using this pugin

  3. isaac feldman Avatar
    isaac feldman

    there is a city that use to be 2 towns and i want to allow shipping to one city – how can i exclude the zipcodes of the town i dont want to ship to?

    1. Condless Avatar

      Hi Isaac,
      You can create shipping zone with that city, and add postcode restriction (built-in in WooCommerce).

  4. Charlie Sanders Avatar
    Charlie Sanders

    Hello! this plugin seems great, but I’m having serious issues at the checkout.
    Price gets updated fine at the cart with the shipping calculator as you can see in this image:
    https://i.ibb.co/B3gFYB4/loikjmsde.png

    When I get to the checkout my two delivery zones are being displayed fine:
    https://i.ibb.co/jL6Nqw9/gtrfedsw.png
    but they wont update the price:
    https://i.ibb.co/7g4TNNj/yhsrdesw.png

    Any idea of what’s going on?
    I would greatly appreciate any hint you can give me!

    1. Condless Avatar

      Hi Charlie,
      Make sure the country field exists on checkout, can you provile the URL of the website?

  5. Carlos Avatar
    Carlos

    Hey!
    Guatemala is not listed in the countries available to use the plugin. We have 22 states here, and would love to add the cities somehow to the plugin. Is this possible?

    1. Condless Avatar

      Hi Carlos,
      Guatamala is not yet supported, you can explore other countries’ cities list in the plugin folder /i18n/cities.

    2. Carlos Avatar
      Carlos

      Hey! Thank you for your reply!

      Is there a way in which I can help to make Guatemala available in the plugin? I am willing to invest some time for it.

      Thank you!

  6. Christian Saborio Avatar
    Christian Saborio

    Costa Rican file, in case you would lie to include it:

    https://1drv.ms/u/s!AuYDDdfI2CCigYH2YqlmmVP5hg-qQx8

    1. Condless Avatar

      Hi Christian,
      Can you provide the source of the list?

    2. Christian Saborio Avatar
      Christian Saborio

      I grabbed the list from this plugin (https://wordpress.org/plugins/wc-provincia-canton-distrito/#description). Changed the JSON included there to the format used by your plugin. Not sure what the original source comes from.

  7. Carlos Avatar
    Carlos

    Hey!

    I have created a document for Guatemala’s cities, updated with all cities available in the country.

    What is the best way to send it to you? In case you want to add it to the plugin.

  8. Arsalan Ahmed Avatar
    Arsalan Ahmed

    Not adding HST? when activating the plugin, as soon as i deactivate the plugin hst works fine

    1. Condless Avatar

      Hi Arsalan,
      See ‘How to apply taxes per city/state?’

  9. Javiera Avatar

    Hola! en Chile, como poder filtrar primero por región y luego por ciudad en 2 listas desplegables, ya que solo me sale una sola lista que incluye en nombre de la región y ciudad, ejemplo:
    Antofagasta – Calama
    Antofagasta -Mejillones

    1. Condless Avatar

      Hola Javiera,
      Try to add new_state field to billing and shipping sections via the Checkout Field Editor plugin.

  10. guneet sharma Avatar
    guneet sharma

    Hi Condless,

    1)How can i add a state as well as cities within a same zone(Country-INDIA)?
    2)And Now in new zone I am not getting state only getting Cities , How to add state only as a complete?

    Thank you

    1. Condless Avatar

      Hi Guneet,
      You can use the Bulk Select tool (via the plugin’s settings), enter the state name/code and the desired shipping zone, and all the cities of that state will be inserted automatically.

  11. Massimo Debattista Avatar
    Massimo Debattista

    Hi
    I programmed the citys my self in the country. As it was taking information from Wikipedia slowing lakes and rivers as cities in MT. My problem is each time it gets plug in updated it is over writes the cities I have put. How can have the plug in that does not show for update.

    1. Condless Avatar

      Hi Massimo,
      You can use the code snippets provided in this docs, to rename or to unset irrelevnt ‘cities’.

  12. Juan Avatar

    Realmente me sirvió muchísimo, estuve buscando mucho como hacer esto para Colombia, y con este plugin fue muy fácil una vez comprendí su funcionamiento, simplemente increíble y adaptable al 100%, seguro dejare 5 estrellas ahora mismo al plugin del repositorio

  13. Luis Enrique Yacupoma Aguirre Avatar

    Best regards, I am happy with the plugin, it is a great job.
    I have a question: I need to establish a single shipping rate for all the districts of a city, is it necessary for me to establish a rate, district by district of the city? Is it possible to establish a single price rate for an entire city?

    1. Condless Avatar

      Hi Luis,
      You can explore the full citis list, and use the ‘Bulk select tool’ (via the plugin’s settings) to insert multiple cities at once.

  14. Juan Carlos Botero Avatar

    Hello a few days ago the dropdown menu for choose the cities/ Region is not working, how can i fix it?

    https://atmosferadigitalcreativa.com/finalizar-compra/

    1. Condless Avatar

      Hi Juan,
      Any changes were made in the website’s settings/configuration/plugins?
      Can you try to deactivate the Checkout Fields Editor plugin?

  15. Mohamad alkabani Avatar
    Mohamad alkabani

    Hello,

    actually I need for the states fields, I’m just looking to add cities in shipping zone

    so I can see country and states and cites.

    Regards,

    1. Condless Avatar

      Hi Mohamad,
      You can choose your country via the plugin’s settings and press ‘Save changes’.

Leave a Reply

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