title: How to make a custom field required based on country on WooCommerce checkout?
body: <p>I've added a custom field to the checkout page (billing_vat) and it needs to be required when the country is set to Ireland (IE).</p>
  
  <p>Currently, I've changed the label to show that it's required in the same way as all the other fields using JavaScript and have hooked into 'woocommerce_get_country_locale' to change the field to required for IE.</p>
  
  <pre class="lang-php prettyprint-override"><code>add_filter('woocommerce_billing_fields', 'dc_custom_billing_fields', 1000, 1);
  function dc_custom_billing_fields( $fields ) {
      $fields['billing_vat'] = array(
          'label'        =&gt; 'VAT Number',
          'required'     =&gt; false,
          'type'         =&gt; 'text',
          'class'        =&gt; array( 'form-row-wide' ),
          'priority'     =&gt; 35,
      );
  
      return $fields;
  }
  
  add_filter( 'woocommerce_get_country_locale', 'dc_change_locale_field_defaults', 1000, 1 );
  function dc_change_locale_field_defaults($countries) {
      $countries['IE']['billing_vat']['required'] = true;
  
      return $countries;
  }
  
  add_action( 'woocommerce_admin_order_data_after_shipping_address', 'dc_display_admin_order_meta', 10, 1 );
  function dc_display_admin_order_meta($order) {
      echo '&lt;p&gt;&lt;strong&gt;'.__('Billing VAT').':&lt;/strong&gt; ' . get_post_meta( $order-&gt;get_id(), '_billing_vat', true ) . '&lt;/p&gt;';
  }
  
  add_action( 'woocommerce_after_order_notes', 'dc_after_checkout_field' );
  function dc_after_checkout_field() {
      ?&gt;
      &lt;script&gt;
          (function($) {
              $(document).ready(function (){
                  $('#billing_country').on('change',function() {
                      if ($('#billing_country').val() == 'IE') {
                          // Required
                          $('#billing_vat').prop('required', true);
                          $('label[for="billing_vat"] .optional').remove();
                          $('label[for="billing_vat"]').append('&lt;abbr class="required" title="required"&gt;*&lt;/abbr&gt;');
                      } else {
                          $('#billing_vat').removeProp('required');
                          $('label[for="billing_vat"] .required').remove();
                          $('label[for="billing_vat"]').append('&lt;span class="optional"&gt;(optional)&lt;/span&gt;');
                      }
                  })
              });
          })(jQuery);
      &lt;/script&gt;
      &lt;?php
  }
  </code></pre>
  
  <p>However when I submit the form, with the country set to Ireland and the field empty, Woo doesn't say that the field is required.</p>