Categories
How to

Add States and Cities to WooCommerce (Provincia, Cantones)

This is a simple guide about how to add States, Cities, and Postcodes relationship to WooCommerce by Country, using the plugin WC Provincia Canton Distrito. This requires access to the source code of your site and minimal knowledge of coding.

Step #1

Copy the main json file from /assets/js/prov-cant-dist.json to /your-theme/assets/js/prov-cant-dist.json. If you don’t need it on this location, you can use the filter wcpcd_prov_cant_dist_json to move it to your custom location.

Step #2

Map your current country, state, city, and postcode information to the json file located in your plugin. As an example, this is part of the mapping information for Ecuador Thanks to José Leones.

Step #3

Map your states to WooCommerce in relation to your country. This is required to become the state field on the Checkout as a dropdown. Based on the same example of Ecuador, you need to use the filter woocommerce_states.

function kmchild_wc_states($states) {
	$states['EC'] = array(
		'A' => 'Azuay',
		'B' => 'Bolívar',
		'P' => 'Pichincha'
	);

	return $states;
}
add_filter('woocommerce_states', 'kmchild_wc_states');

Result

Now, you’ll be able to choose Country (optional), State, State-District and it places the postcode related to the postcode field.

I hope that these instructions help you to use this plugin with your country information. Don’t hesitate to contact me in case you need anything else.

By KeylorCR

Hello world. My name is Keylor Mendoza from Costa Rica, a WordPress Developer with more than 5 years of experience working with custom themes and plugins. Strong experience working with WooCommerce customizations.

Leave a Reply

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