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. Mohamed Avatar
    Mohamed

    Hi
    I tried it for Morocco but dont work.
    Any idea ?

    1. Condless Avatar

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

  2. roberto stoute Avatar

    Cual seria el formato para Región(es) de la zona Bulk Select
    en el caso de colombina Bogotá

    1. Condless Avatar

      Hola roberto
      Puede explorar los códigos de regiones / ciudades en esta lista, entre cada código debe estar ;, por ejemplo: CO11; CO13; CO05001;

    2. Condless Avatar

      Aparece algún error? Colombia debe seleccionarse en el primer campo de la configuración. las ubicaciones deben aparecer en la configuración de envío de woocommerce.

    3. Roberto Alexis Stoute Avatar

      esta opción
      Enable to be able to apply distance fee in flat rate shipping methods

      no funciona

  3. Roberto Alexis Stoute Avatar

    sale este error
    El país de la tienda no se seleccionó o no admite la tarifa de distancia de envío

    1. Condless Avatar

      Se le enviaron imágenes con explicación por email

  4. Ennyboss Avatar
    Ennyboss

    Please I just installed your plugin. I intend to use the city dropdown for the shipping zone which works. but i keep getting this error after saving changes “Undefined Array key /home/mrtoolsc/public_html/wp-content/plugins/cities-shipping-zones-for-woocommerce/cities-shipping-zones-for-woocommerce.php on line 769” I use the country only Nigeria

    Please What can i do, i get this error on my website and my ecommerce dashboard

    1. Condless Avatar

      Hi Ennyboss,
      Whats your website URL? Please try to disable the ‘Selling locations’ option (via the plugin settings).

    2. Ennyboss Avatar

      It is still the same thing, i still get the errors and even on the checkout page
      it also writes this
      “please note, your country is set to municipaities and not cities”

  5. Ennyboss Avatar
    Ennyboss

    Hi Condless, okay, when i disabled the selling location, it cleared the error on the main website. but on my dashboard, i notice i have to input states in different shipping zone before the error clears off one after the other.

    and please how i select a whole state as a shipping zone, as in removing cities in some state.
    thank you. I await your feedback

    1. Condless Avatar

      Try using the Bulk Select tool (in the plugin settings), you can insert a state name/code- then all its cities will be inserted automatically into the selected shipping zone.

  6. nhletelo shirinda Avatar
    nhletelo shirinda

    For South africa – Limpopo there are missing cities which i want them to be added “Giyani” and “Malamulele

    1. Condless Avatar

      Hi Nhletelo,
      The cities was added, you can redownload the plugin to have it.

  7. Rodrigo Avatar
    Rodrigo

    hi, i use this plugin and works fantastic, but need a help.

    In order details and email my “billing_state” is for example “cl451”, but need the “name”, note the code.

    woocommerce_formatted_address_replacements maybe work, but idont know how implement it, maybe you can give me an example.

    Thank you

    1. Condless Avatar

      Hi Rodrigo,
      Can you share the website URL?
      Please make sure the country field is present on the checkout page.

    2. Condless Avatar

      Hi,
      The conutry field must be enabled via the Checkout Fields Editor plugin.

    3. Rodrigo Avatar

      But idont need country field, need only state/cities. I need help with this:

      “Why the state code and not the state name appears in the order details in the first order email confirmation and in the my account section while using the State Autofill option on countries with WooCommerce built-in states list?
      You can use the woocommerce_formatted_address_replacements filter to fix it.”

      Need state/cities name, not the code in order

    4. Condless Avatar

      The country field must be enabled via the plugin, you can hide it using the CSS:
      #billing_country_field {
      display: none;
      }

  8. Destiny Orinameh Alabi Avatar
    Destiny Orinameh Alabi

    Hi, Nice plugin. However when this is activated, it totally disable states why. I want to be able to use states too for my shipping and combine with with cities

    1. Condless Avatar

      Hi,
      Please try to enable the State Autofill and the Filters options (via the plugin settings).

  9. Web n Ko Avatar
    Web n Ko

    Hi Condless Team,
    I install your plugin for Morocco and it’s work very well.
    Now i try to put some cities in the top of dropdown in the order page.
    I tried your solution but don’t where an how to put it for positionning like 10 cities in the top of the dropdown.
    Many thanks for your help

    1. Condless Avatar

      Hi,
      The docs was updated to include the code that put some cities in the top of dropdown, update the code as follow:
      $country = 'MA';
      $first_keys = [ 'MA042810105', 'MA042810301' ]; // the codes of the cities which should be at the top

    2. Web n Ko Avatar
      Web n Ko

      Hi
      Thanks for your quick answer but where do I put this Code; in the function.php of in the MA.php ? I’m lost
      Thanks for your answer

    3. Condless Avatar

      Hi,
      In the functions.php

  10. vlad Avatar
    vlad

    Hello Condless! Please add the list of regions (cities) of Ukraine (UA) to your plugin.

    1. Condless Avatar

      Hi Vlad,
      Ukraine is supported, select it in the plugin settings and press the ‘Save Changes’ button.

  11. nick Avatar
    nick

    hi there, how can i set state as Default during checkout?

    1. Condless Avatar

      Hi,
      You can set the location of the store and select ‘Shop Base’ in the Default Customer Address option (WooCommerce General Settings).

  12. Jose Avatar
    Jose

    Hi,

    Can Guatemala be added to user with your plugin? thanks

    1. Condless Avatar

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

    2. Jose Avatar
      Jose

      Just the send the email. But all I am looking for is to add Guatemala like Ukraine or other request.

  13. Jes Avatar
    Jes

    Hi
    Trying to use the pligin wondering if you added data for Kenya?

    1. Condless Avatar

      Hi Jes,
      Kenya is supported

  14. Magdi Alkelani Avatar
    Magdi Alkelani

    Hello,

    Could You please Add Oman to the Coutnry List you support, i really love how your plugin works,

    Thanks in Advance

    1. Condless Avatar

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

  15. Muhammad Abdulrazek Avatar
    Muhammad Abdulrazek

    Hello ,
    I am trying to make a flat rate of 9 riyal for only one place in saudi arabia & 35 Riyal Flat Rate for rest of country
    Can You Help Me My Friend ?

Leave a Reply to Daniela Cancel reply

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