-
-
Save mikejolley/3123868 to your computer and use it in GitHub Desktop.
/** | |
* Code goes in functions.php or a custom plugin. | |
*/ | |
add_filter( 'woocommerce_states', 'indian_woocommerce_states' ); | |
function indian_woocommerce_states( $states ) { | |
$states['IN'] = array( | |
'AP' => __('Andra Pradesh', 'woocommerce'), | |
'AR' => __('Arunachal Pradesh', 'woocommerce'), | |
'AS' => __('Assam', 'woocommerce'), | |
'BR' => __('Bihar', 'woocommerce'), | |
'CT' => __('Chhattisgarh', 'woocommerce'), | |
'GA' => __('Goa', 'woocommerce'), | |
'GJ' => __('Gujarat', 'woocommerce'), | |
'HR' => __('Haryana', 'woocommerce'), | |
'HP' => __('Himachal Pradesh', 'woocommerce'), | |
'JK' => __('Jammu and Kashmir', 'woocommerce'), | |
'JH' => __('Jharkhand', 'woocommerce'), | |
'KA' => __('Karnataka', 'woocommerce'), | |
'KL' => __('Kerala', 'woocommerce'), | |
'MP' => __('Madhya Pradesh', 'woocommerce'), | |
'MH' => __('Maharashtra', 'woocommerce'), | |
'MN' => __('Manipur', 'woocommerce'), | |
'ML' => __('Meghalaya', 'woocommerce'), | |
'MZ' => __('Mizoram', 'woocommerce'), | |
'NL' => __('Nagaland', 'woocommerce'), | |
'OR' => __('Orissa', 'woocommerce'), | |
'PB' => __('Punjab', 'woocommerce'), | |
'RJ' => __('Rajasthan', 'woocommerce'), | |
'SK' => __('Sikkim', 'woocommerce'), | |
'TN' => __('Tamil Nadu', 'woocommerce'), | |
'TR' => __('Tripura', 'woocommerce'), | |
'UT' => __('Uttaranchal', 'woocommerce'), | |
'UP' => __('Uttar Pradesh', 'woocommerce'), | |
'WB' => __('West Bengal', 'woocommerce'), | |
'AN' => __('Andaman and Nicobar Islands', 'woocommerce'), | |
'CH' => __('Chandigarh', 'woocommerce'), | |
'DN' => __('Dadar and Nagar Haveli', 'woocommerce'), | |
'DD' => __('Daman and Diu', 'woocommerce'), | |
'DL' => __('Delhi', 'woocommerce'), | |
'LD' => __('Lakshadeep', 'woocommerce'), | |
'PY' => __('Pondicherry (Puducherry)', 'woocommerce') | |
); | |
return $states; | |
} |
In which file should I paste these codes to add Indian States. Can some one help me with its url Path? (which function.php, for there is for both theme and plugin as well)
Hi Mike,
The state code 'UT' => __('Uttaranchal', 'woocommerce'), should bechanged to 'UK' => __('UttarKhand','woocommerce'). I came to know this when I tried applying taxes to states and checked each state in the checkout to make sure taxes are applied. It failed for this state. So I reconfirmed this using $country_states_array = WC()->countries->get_states('IN'); and it returned value [UK] => Uttarakhand .
If you are using Woocomerce Export plugin then the "billing_state_code" can be mapped to "Place of Supply" field in GSTR1 (when you are importing 100s of transactions from a .csv file)
List of valid codes for states and union territories:
IMPORTANT NOTE: You must change state codes accordingly in Tax Rates Table under example.com/wp-admin/admin.php?page=wc-settings&tab=tax§ion=standard.
For exapmle: "KA" becomes "29-Karnataka".
/**
* Code goes in functions.php or a custom plugin.
*/
add_filter( 'woocommerce_states', 'indian_woocommerce_states' );
function indian_woocommerce_states( $states ) {
$states['IN'] = array(
'35-AndamanandNicobarIslands' => __('Andaman and Nicobar Islands', 'woocommerce'),
'37-AndhraPradesh' => __('Andhra Pradesh', 'woocommerce'),
'12-ArunachalPradesh' => __('Arunachal Pradesh', 'woocommerce'),
'18-Assam' => __('Assam', 'woocommerce'),
'10-Bihar' => __('Bihar', 'woocommerce'),
'04-Chandigarh' => __('Chandigarh', 'woocommerce'),
'22-Chattisgarh' => __('Chattisgarh', 'woocommerce'),
'26-DadraandNagarHaveli' => __('Dadra and Nagar Haveli', 'woocommerce'),
'25-DamanandDiu' => __('Daman and Diu', 'woocommerce'),
'07-Delhi' => __('Delhi', 'woocommerce'),
'30-Goa' => __('Goa', 'woocommerce'),
'24-Gujarat' => __('Gujarat', 'woocommerce'),
'06-Haryana' => __('Haryana', 'woocommerce'),
'02-HimachalPradesh' => __('Himachal Pradesh', 'woocommerce'),
'01-JammuandKashmir' => __('Jammu and Kashmir', 'woocommerce'),
'20-Jharkhand' => __('Jharkhand', 'woocommerce'),
'29-Karnataka' => __('Karnataka', 'woocommerce'),
'32-Kerala' => __('Kerala', 'woocommerce'),
'31-LakshadweepIslands' => __('Lakshadweep Islands', 'woocommerce'),
'23-MadhyaPradesh' => __('Madhya Pradesh', 'woocommerce'),
'27-Maharashtra' => __('Maharashtra', 'woocommerce'),
'14-Manipur' => __('Manipur', 'woocommerce'),
'17-Meghalaya' => __('Meghalaya', 'woocommerce'),
'15-Mizoram' => __('Mizoram', 'woocommerce'),
'13-Nagaland' => __('Nagaland', 'woocommerce'),
'21-Odisha' => __('Odisha', 'woocommerce'),
'34-Pondicherry' => __('Pondicherry', 'woocommerce'),
'03-Punjab' => __('Punjab', 'woocommerce'),
'08-Rajasthan' => __('Rajasthan', 'woocommerce'),
'11-Sikkim' => __('Sikkim', 'woocommerce'),
'33-TamilNadu' => __('Tamil Nadu', 'woocommerce'),
'36-Telangana' => __('Telangana', 'woocommerce'),
'16-Tripura' => __('Tripura', 'woocommerce'),
'09-UttarPradesh' => __('Uttar Pradesh', 'woocommerce'),
'05-Uttarakhand' => __('Uttarakhand', 'woocommerce'),
'19-WestBengal' => __('West Bengal', 'woocommerce'),
);
return $states;
}
@mikejolley Thank you!
@mikejolley Is there a code to restrict the Pincodes and the Town City from the state ?
why not include this into the core?