Restrict WooCommerce Shipping Calculator to Specific Countries and States

Here is how you can restrict specific Countries and States in WooCommerce Shipping Calculator, so a user can only select from what is available.

Countries

The Countries field is handled inside WooCommerce General Settings. Change the ‘Selling Location’ to ‘Sell to specific countries then add the countries you want in the next field.

Woocommerce Ship Specific Country

States

For states you will need to add in some code to your themes functions.php file

add_filter( 'woocommerce_states', 'em_custom_woocommerce_states' );
/**
 * Ship to only one state e.g. QLD in Australia
 */
function em_custom_woocommerce_states( $states ) {
	$states['AU'] = array(
	'QLD' => 'Queensland',
	);
	return $states;
}

So in the code above a WooCommerce filter is run on the states in Australia using the 2 digit code AU with only the state digit code QLD returned, short for Queensland.

Show Certain States Woocommerce

Here is a reference that has all country codes which click though to state codes for those countries.

Leave all Comment