Verify VAT(EU) number + tax exemption
You should do these actions
1. Install/activate plugin https://wordpress.org/plugins/woocommerce-eu-vat-assistant/
2. Visit “WooCommerce” – “Phone Orders” – “Settings” – “Customers” and mark checkbox “Show field “VAT Number”
3. Add following PHP code to functions.php (child theme!) OR using plugin https://wordpress.org/plugins/code-snippets/
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | // Before using this code you must  // - install https://wordpress.org/plugins/woocommerce-eu-vat-assistant/ // - mark "Show field Vat Numbe"  in  >Phone Orders>Settings>Customers add_filter( 'wpo_after_update_customer', function($customer, $request ){  if($customer['custom_fields']['vat_number']  AND class_exists("AeliaWCEU_VAT_AssistantEU_VAT_Validation") ) {   $vat_number = $customer['custom_fields']['vat_number'];   $customer_country = substr($vat_number,0,2);   $shop_country = WC_Countries::get_base_country();   $validation = AeliaWCEU_VAT_AssistantEU_VAT_Validation::factory();   $raw_vat_validation_response = $validation->validate_vat_number($customer_country, $vat_number);   if($raw_vat_validation_response['valid'] == true) {     /* An EU customer will be considered exempt from VAT if:       * - He is located in a country different from shop's base country.       * - He is located in the same country as the shop, and option "remove VAT       *   when customer in located in shop's base country" is enabled.       */     if( ($customer_country != $shop_country) || AeliaWCEU_VAT_AssistantWC_Aelia_EU_VAT_Assistant::settings()->get(AeliaWCEU_VAT_AssistantSettings::FIELD_REMOVE_VAT_IF_CUSTOMER_IN_BASE_COUNTRY) ) {       $customer['is_vat_exempt']= true;     }   }     else {     $customer['is_vat_exempt']= false;     //rebuld HTML, mark in red     $customer['formatted_billing_address']  = preg_replace( '#>Vat number: (.*?)<#s', '>Vat number: <span class="wpo_custom_field required-field">' . $customer['custom_fields']['vat_number'] . '</span><',  $customer['formatted_billing_address']);   }    }  return $customer; },10,2); |