Make state checkout field required for a specific country in Woocommerce
up vote
1
down vote
favorite
The country of Vietnam in Woocommerce does not have the states, so I
added some states to my checkout page.
This is my code:
add_filter( 'woocommerce_states', 'vietnam_cities_woocommerce' );
function vietnam_cities_woocommerce( $states )
$states['VN'] = array(
'HCM' => __('Hồ Chí Minh', 'woocommerce') ,
'HANOI' => __('Hà Nội', 'woocommerce') ,
'HAIPHONG' => __('Hải Phòng', 'woocommerce') ,
);
return $states;
It do work as I would like, but it is an optional field for Vietnam.
How to make this state field as required for Vietnam?
Any help is appreciated.
php wordpress woocommerce field checkout
add a comment |
up vote
1
down vote
favorite
The country of Vietnam in Woocommerce does not have the states, so I
added some states to my checkout page.
This is my code:
add_filter( 'woocommerce_states', 'vietnam_cities_woocommerce' );
function vietnam_cities_woocommerce( $states )
$states['VN'] = array(
'HCM' => __('Hồ Chí Minh', 'woocommerce') ,
'HANOI' => __('Hà Nội', 'woocommerce') ,
'HAIPHONG' => __('Hải Phòng', 'woocommerce') ,
);
return $states;
It do work as I would like, but it is an optional field for Vietnam.
How to make this state field as required for Vietnam?
Any help is appreciated.
php wordpress woocommerce field checkout
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
The country of Vietnam in Woocommerce does not have the states, so I
added some states to my checkout page.
This is my code:
add_filter( 'woocommerce_states', 'vietnam_cities_woocommerce' );
function vietnam_cities_woocommerce( $states )
$states['VN'] = array(
'HCM' => __('Hồ Chí Minh', 'woocommerce') ,
'HANOI' => __('Hà Nội', 'woocommerce') ,
'HAIPHONG' => __('Hải Phòng', 'woocommerce') ,
);
return $states;
It do work as I would like, but it is an optional field for Vietnam.
How to make this state field as required for Vietnam?
Any help is appreciated.
php wordpress woocommerce field checkout
The country of Vietnam in Woocommerce does not have the states, so I
added some states to my checkout page.
This is my code:
add_filter( 'woocommerce_states', 'vietnam_cities_woocommerce' );
function vietnam_cities_woocommerce( $states )
$states['VN'] = array(
'HCM' => __('Hồ Chí Minh', 'woocommerce') ,
'HANOI' => __('Hà Nội', 'woocommerce') ,
'HAIPHONG' => __('Hải Phòng', 'woocommerce') ,
);
return $states;
It do work as I would like, but it is an optional field for Vietnam.
How to make this state field as required for Vietnam?
Any help is appreciated.
php wordpress woocommerce field checkout
php wordpress woocommerce field checkout
edited Nov 8 at 10:50
LoicTheAztec
77.6k125991
77.6k125991
asked Nov 4 at 3:45
Lê Nghĩa
536
536
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The following function will make for Vietnam the state field as a required in woocommerce:
add_filter( 'woocommerce_get_country_locale', 'custom_country_locale', 10, 1 );
function custom_default_address_fields( $locale )
$locale['VN']['state']['required'] = true;
return $locale;
Code goes in function.php file of your active child theme (active theme). Tested and works.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The following function will make for Vietnam the state field as a required in woocommerce:
add_filter( 'woocommerce_get_country_locale', 'custom_country_locale', 10, 1 );
function custom_default_address_fields( $locale )
$locale['VN']['state']['required'] = true;
return $locale;
Code goes in function.php file of your active child theme (active theme). Tested and works.
add a comment |
up vote
1
down vote
accepted
The following function will make for Vietnam the state field as a required in woocommerce:
add_filter( 'woocommerce_get_country_locale', 'custom_country_locale', 10, 1 );
function custom_default_address_fields( $locale )
$locale['VN']['state']['required'] = true;
return $locale;
Code goes in function.php file of your active child theme (active theme). Tested and works.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The following function will make for Vietnam the state field as a required in woocommerce:
add_filter( 'woocommerce_get_country_locale', 'custom_country_locale', 10, 1 );
function custom_default_address_fields( $locale )
$locale['VN']['state']['required'] = true;
return $locale;
Code goes in function.php file of your active child theme (active theme). Tested and works.
The following function will make for Vietnam the state field as a required in woocommerce:
add_filter( 'woocommerce_get_country_locale', 'custom_country_locale', 10, 1 );
function custom_default_address_fields( $locale )
$locale['VN']['state']['required'] = true;
return $locale;
Code goes in function.php file of your active child theme (active theme). Tested and works.
answered Nov 4 at 9:59
LoicTheAztec
77.6k125991
77.6k125991
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53137583%2fmake-state-checkout-field-required-for-a-specific-country-in-woocommerce%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password