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/
// 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("Aelia\WC\EU_VAT_Assistant\EU_VAT_Validation") ) {
$vat_number = $customer['custom_fields']['vat_number'];
$customer_country = substr($vat_number,0,2);
$shop_country = WC_Countries::get_base_country();
$validation = Aelia\WC\EU_VAT_Assistant\EU_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) || Aelia\WC\EU_VAT_Assistant\WC_Aelia_EU_VAT_Assistant::settings()->get(Aelia\WC\EU_VAT_Assistant\Settings::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);