I have wordpress website which runs woocommerce. When the customer selects country in the check out form a list of counties come as drop down but the field is showing as not required. I also want a * to come around the label. How can I do this ?
Apply the following Gist, but change false
to true
:
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;
}
I tested this, and it is working.
The other option, i.e., to use filter woocommerce_default_address_fields
as described here did NOT work.