• Resolved gresakg

    (@gresakg)


    Is it possible to make VAT number required only for one country, namely the country of the shop? All other EU countries can proceed without the VAT number?

    If it requires programming a small extension it is not a problem for me, I would only need a hint as for where to hook it.

    Thanks, Greg

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Diego

    (@daigo75)

    The EU VAT Assistant offers a filter called wc_aelia_euva_order_is_eu_vat_number_required, which can be used to set the VAT number as “required” using custom logic. Here’s a template for such filter, to get you started:

    
    add_filter('wc_aelia_euva_order_is_eu_vat_number_required', function($vat_number_required, $customer_country) {
      if(<YOUR CUSTOM CHECK>) {
        $vat_number_required = true;
      }
      return $vat_number_required;
    }, 10, 2);
    

    Note
    The code is an example, provided as-is, without implicit or explicit warranties, and it’s outside the scope of our support service. We recommend to test it on a staging site, before using it on a live site.

    Thread Starter gresakg

    (@gresakg)

    Hi, thanks, this works. However, it only affects the backend. On the form, the field remains marked as optional. How could I change this?

    Thanks again, Greg

    Thread Starter gresakg

    (@gresakg)

    Just for the record: I solved this problem too by hooking into woocommerce_checkout_fields, after the VAT field has been created, that is at priority 41.

    add_filter('woocommerce_checkout_fields', function($fields) {
    
      if(wc()->customer->get_billing_country() == wc()->countries->get_base_country()) {
        $fields['billing']['vat_number']['required'] = true;
      }
      return $fields;
    },45);
    Plugin Author Diego

    (@daigo75)

    The filter I sent you applies to the frontend, there isn’t a check for the VAT number being required in the backend. Please note that the filter doesn’t affect the display of the field (if it appears as “optional”, it’s because of the reasons explained here: https://www.ads-software.com/support/topic/how-to-remove-the-optional-label-from-the-checkout-fields-updated/), but it forces the VAT number to be required when the customer tries to complete the checkout.

    The filter you added will make the VAT number field required on page load, but it won’t handle the condition in which the billing country changes. If the VAT number field is marked as required within woocommerce_checkout_fields, then it will stay required no matter what country you choose at checkout.

    Thread Starter gresakg

    (@gresakg)

    Thanks for the update, the explanation and the warning of a potential caveat in my solution.
    I will now have to figure out what will work best for my usecase.
    I think you can safely close this ticket now.

    Thanks alot and all best! Greg

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘VAT number requred for one country’ is closed to new replies.