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. 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/

    I found the problem, inspecting the page using the F12 key in Google Chrome, I found that when inspecting the element “name=billing_state” and “id=billing_state”, in my case it has a CSS class called class=”state_select slect2-hidden -accessible” which generates a conflict, since if I change the class name in the inspector leaving it only as class=”state_select” the drop down works correctly with some error since it appears duplicate but now it allows clicking and is displayed. Could you tell me what causes this and how can I solve it? I still have the error since I do not have the file, I must modify it for the change to be effective on the page.

    1. Condless Avatar

      Hi Juan,
      Please try to deactivate the Checkout Fields Editor plugin.

  2. Cristian Morales Kallina Avatar

    Dear, grateful for your plugin, I need to somehow change the text “Country / Region” to “PaĆ­s”, but it hasn’t worked for me. Could you help me how to change it.

    1. Condless Avatar

      Hi Cristian,
      The plugin doesn’t have any affect on this text, you can use the second code from this answer:
      https://stackoverflow.com/a/65266234

  3. Collins Avatar

    How do I add cities and where do I paste these codes

  4. Jorge Hurtado Avatar

    Hey hi. Thanks for this plugins, is a great idea. I dont know if is possible, change the list of cities in the file named CO.php where there is a list like this:
    ‘CO05’ => [
    ‘CO05313’ => ‘Granada’,
    For this:
    ‘CO05’ => [
    ‘CO05313’ => ‘Granada, Antioquia (add state in the end)’,

    And this is because many of them are repeated, i mean, in two states exists the same city, for example:
    ‘CO05’ => [
    ‘CO05055’ => ‘Argelia’, (is Antioquia State)
    And:
    ‘CO19’ => [
    ‘CO19050’ => ‘Argelia’, (is Cauca State)

    In fact, i made it, but when i update de plugin, the changes made it, are gone. If you want, i give you the file for Colombia Country CO.php, that is ready.

    1. Condless Avatar

      Hi Jorge,
      See in the docs:
      “How to modify cities names?”
      or enable the ‘Filters’ option (via the Cities plugin settings).

  5. hanees Avatar

    hi nice plugin
    from srilanka
    i have created 2 zone and load cities to zone with different shipping Chages
    so when i change cities in front it not chenging
    it get first zone in list

    1. Condless Avatar

      Hi Hanees,
      The shipping zone which contains the cities should be on the top of the shipping zones list.

  6. Mohammad Avatar
    Mohammad

    I have an issue when changing the shipping price, It is not changing directly in the order table (in the checkout page)

    Not refreshing automatically like the default wooocmmerce plugin.

    1. Condless Avatar

      Hi Mohammad,
      What’s the website URL? does it work ok when deactivating the Cities plugin?

  7. Diego Avatar

    Hi,
    How can I add the country Argentina?
    When I add it in the settings it tells me that I need to contact support to add it.

  8. Ken Avatar
    Ken

    Hi

    I’m getting the error for each shipping region. Here’s one:
    Warning: Undefined array key “EE446” in …/wp-content/plugins/woocommerce/includes/class-wc-shipping-zone.php on line 130

    Already tried to reactivate the plugin.
    What else can I do about it?

    1. Condless Avatar

      Hi Ken,
      Which pages produce that error?

    2. Ken Juks Avatar
      Ken Juks

      Hi

      In WP admin Woocommerce > Orders produce the errors. Just in top of the order list.

      Thanks,
      Ken

    3. Condless Avatar

      Hi,
      This shouldn’t affect plugin’s functionality, you can disable the debug log to hide those errors.

  9. Ken Juks Avatar
    Ken Juks

    Hi

    Added the following to wp-config did the work:

    ini_set(‘display_errors’,’Off’);
    ini_set(‘error_reporting’, ‘E_ALL’ );
    define(‘WP_DEBUG’, false);
    define(‘WP_DEBUG_DISPLAY’, false);

    Thank you!
    Ken

  10. Radhika Avatar
    Radhika

    Please help me with the list of city codes for indonesia, where can I find it

    1. Condless Avatar

      Hi Radhika,
      The cities codes is in the plugin’s folder /i18n/cities.

  11. Raaya Avatar
    Raaya

    I am using the WCFM – WooCommerce Frontend Manager plugin. It seems like there is an integration with Cities Shipping Zones in their system, because I see that once an admin created a Shipping Zone, the vendor can see this zone and chose it in his system (Store Manager > Settings > Shipping > Shipping Type > Shipping by Zone). However, the vendor cannot create a zone by himself, only use a zone that was previously defined by an admin.

    Is there a way for me to have the admin’s Add Zone functionality per Store Vendor role in the Store Manager’s system?

    1. Condless Avatar

      Hi Raaya,
      There is no option for WCFM vendors to create Shipping Zones, the admin should create all the relevant/required Shipping Zones and let the vendors choose from them.

  12. Sahnoun Oualid Avatar

    I have a problem which is City and Area fields are optionals when I choose UAE

    1. Condless Avatar

      Hi Sahnoun,
      By default the city field is required and the area field is optional, if you use some Checkout Fields Editor plugin it may be different.

Leave a Reply

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