Home » Php » Make Woocommerce checkout state field required

Make Woocommerce checkout state field required

Posted by: admin September 25, 2018 Leave a comment


So this problem may have a easy solution, but I’m stuck for the moment. After the last update (Woocommerce 3.3.5) I have a problem with the state field on the checkout page, because it is not mandatory and people just skip it. I really need this thing to be mandatory, because I have connected my website to the delivery company server through and API to send the order info directly to them.

I tried adding this to my functions.php and the thing is that when I go to the checkout page, the field has an asterisk, but for like one second.

add_filter( 'woocommerce_billing_fields', 'woo_filter_state_billing', 
10, 1 );
add_filter( 'woocommerce_shipping_fields', 
'woo_filter_state_shipping', 10, 1 );

function woo_filter_state_billing( $address_fields ) { 
$address_fields['billing_state']['required'] = true;
return $address_fields;
function woo_filter_state_shipping( $address_fields ) { 
$address_fields['shipping_state']['required'] = true;
return $address_fields;

Any help is appreciated. Thanks!