How to prevent checkout in billing_country dropdown field if option is not selected


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 
           $replace = esc_html__( 'Select option to pay correct tax', 'woocommerce' ); // Replacement 
         $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;
Peter Rossetti 1 month 0 Answers 6 views 0

Leave an answer