wooCommerce checkout page State / County (optional) validate not working

that is my added code

 add_filter(‘thwcfd_State_field_override_required’,’__return_true’);

any idea for how to add mandatory for the State / County (optional)

like as State / County (optional)*

look my issue

enter image description here

  • 1
    hi ok i send solution for you – vikrant zilpe Nov 30 at 8:55
  • @vikrantzilpe ok thanks – core114 Nov 30 at 8:56
  • 1
    please send state/ country field name – vikrant zilpe Nov 30 at 9:16
  • 1
    See this, function SA_woocommerce_states( $states ) { $states['LK']['CK'] = __('Colombo', 'woocommerce'); $states['LK']['RT'] = __('Kandy', 'woocommerce'); return $states; } – core114 Nov 30 at 9:17
  • 1
    Sri, yesterday you given n some solution for me, look wordpress.stackexchange.com/questions/320546/… – core114 Nov 30 at 9:19
up vote 1 down vote accepted

Code goes in function.php file of your active child theme (or active theme). It could works.

add_filter( 'woocommerce_billing_fields', 'woo_filter_state_billing', 10, 1 ); 
function woo_filter_state_billing( $address_fields ) { 
    $address_fields['billing_state']['required'] = true;
    return $address_fields; 
} 

add_filter( 'woocommerce_shipping_fields', 'woo_filter_state_shipping', 10, 1 );
function woo_filter_state_shipping( $address_fields ) { 
    $address_fields['shipping_state']['required'] = true; 
    return $address_fields; 
}
  • hello sir, sorry its not working , i want to validate ``State / County (optional)` please check my updated question – core114 Nov 30 at 9:08
  • ok i check and send new update – vikrant zilpe Nov 30 at 9:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.