I have a woocommerce website. by default in woocommerce i can limit shipping zones by zipcode.... But How can I add states of my country in shipping zones so that customers can
If states are not defined for your country in WooCommerce, you should need to defined them all with a letter code (2 or 3 uppercase characters) and the corresponding label name in an array.
Here below is an example based on France regions (Not defined in Woocommerce) for France country code 'FR'
(so you need to set your woocommerce country code):
add_filter('woocommerce_states', 'add_custom_states_to_country');
add_filter('woocommerce_countries_allowed_country_states', 'add_custom_states_to_country');
function add_custom_states_to_country( $states ) {
$states['FR'] = array(
'AR' => __('Auvergne-Rhône-Alpes', 'woocommerce'),
'BF' => __('Bourgogne-Franche-Comté', 'woocommerce'),
'BR' => __('Bretagne', 'woocommerce'),
'CV' => __('Centre-Val-de-Loire', 'woocommerce'),
'CO' => __('Corse', 'woocommerce'),
'IF' => __('Île-de-France', 'woocommerce'),
'GE' => __('Grand Est', 'woocommerce'),
'HF' => __('Hauts-de-France', 'woocommerce'),
'NO' => __('Normandie', 'woocommerce'),
'NA' => __('Nouvelle-Aquitaine', 'woocommerce'),
'OC' => __('Occitanie', 'woocommerce'),
'PL' => __('Pays de la Loire', 'woocommerce'),
'PA' => __('Provence-Alpes-Côte d’Azur', 'woocommerce'),
);
return $states;
}
Code goes in function.php file of your active child theme (or active theme). tested and works.
The Country Iso Codes
In Shipping Zone Settings:
In Cart (shipping calculator):
In Checkout: