Why required field not working in Country dropdown in WooCommerce –
Question
The title might seem a simple fix but it is indicating it is a required field – yet checkout is allowed without an option being chosen and the select option just showing.
I have the following functions running in the function.php of the child theme – anybody see any conflict?
add_filter( 'woocommerce_form_field_country', 'filter_form_field_country', 10, 4 );
function filter_form_field_country( $field, $key, $args, $value ) {
// Only in checkout page for "billing" city field
if ( is_checkout() && 'billing_country' === $key ) {
$search = esc_html__( 'Select a country / region…', 'woocommerce' ); // String to
search
$replace = esc_html__( 'Select option to pay correct tax', 'woocommerce' ); // Replacement
string
$field = str_replace( $search, $replace, $field );
}
return $field;
}
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_country']['label'] = __('Are you purchasing as a Company Y/N or from
the UK?', 'woocommerce');
$fields['billing']['billing_country']['required'] = true;
return $fields;
}
0
1 month
0 Answers
11 views
0
Leave an answer
You must login or register to add a new answer .