Verify VAT(EU) number + tax exemption
For stores that sell to EU businesses, validating a customer’s VAT number and automatically applying tax exemption is essential for legal compliance. This guide shows you how to integrate the WooCommerce EU VAT Assistant plugin with Phone Orders for WooCommerce. When an agent creates a manual order, the plugin validates the customer’s VAT number and automatically marks the order as tax‑exempt if the number is valid.
Prerequisite: This integration requires the Pro version of Phone Orders for WooCommerce.
How the VAT Validation Works
The integration uses the WooCommerce EU VAT Assistant plugin to validate VAT numbers against the official VIES database. When an agent creates a phone order:
- The agent enters a VAT number in the customer’s profile.
- The plugin sends the VAT number to the EU VAT Assistant for validation.
- If the number is valid:
- If the number is invalid:
Prerequisites
Before implementing the code, complete the following steps:
Step 1: Install the EU VAT Assistant plugin
Install and activate the free WooCommerce EU VAT Assistant plugin from the WordPress repository.
Step 2: Enable the VAT number field in Phone Orders
- Go to WooCommerce → Phone Orders → Settings.
- Click the Customers tab.
- Locate the option Show field “VAT Number” and tick the checkbox.
- Click Save settings.
Step 3: Configure EU VAT Assistant settings
The VAT Assistant plugin has its own settings. Ensure it is correctly configured for your store’s base country and tax rules.
The Complete Code Snippet
Copy and paste the following code into your child theme’s functions.php file or via the Code Snippets plugin.
|
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); |
What the Code Does
| Element | Explanation |
|---|---|
add_filter( 'wpo_after_update_customer', ... ) | Runs the code after the phone order interface saves or updates a customer. |
! empty( $customer['custom_fields']['vat_number'] ) | Checks whether the customer has a VAT number entered. |
class_exists( "AeliaWCEU_VAT_AssistantEU_VAT_Validation" ) | Confirms the EU VAT Assistant plugin is active. |
substr( $vat_number, 0, 2 ) | Extracts the first two characters of the VAT number to determine the customer’s country (e.g., DE, FR, IT). |
WC_Countries::get_base_country() | Retrieves the store’s base country from WooCommerce settings. |
AeliaWCEU_VAT_AssistantEU_VAT_Validation::factory() | Creates an instance of the EU VAT Assistant validation class. |
validate_vat_number( $customer_country, $vat_number ) | Performs the actual validation against the VIES database. Returns an array with a valid key. |
$remove_vat_if_in_base | Reads the EU VAT Assistant setting that determines whether customers in the base country should still be tax‑exempt when they have a valid VAT number. |
$customer['is_vat_exempt'] = true | Marks the order as tax‑exempt. WooCommerce respects this flag during tax calculation. |
$customer['is_vat_exempt'] = false | Ensures the order is not tax‑exempt if the VAT number is invalid. |
preg_replace(...) | Highlights the invalid VAT number in red in the customer’s billing address display. |
Step‑by‑Step Implementation
Step 1: Install the required plugins
- Phone Orders for WooCommerce (Pro version)
- WooCommerce EU VAT Assistant (free, from WordPress.org)
Step 2: Enable the VAT number field in Phone Orders
- Go to WooCommerce → Phone Orders → Settings → Customers.
- Tick Show field “VAT Number”.
- Click Save settings.
Step 3: Add the code snippet
Follow the same method as described in Section 1.5:
- Use the Code Snippets plugin (recommended) or add the code to your child theme’s
functions.php. - Title the snippet e.g., “Phone Orders – EU VAT Validation”.
- Activate the snippet.
Step 4: Test the integration
- Open a phone order and select or create a customer.
- Enter a valid EU VAT number (e.g.,
DE123456789– use a real VIES‑valid number for testing). - Save the customer.
- Add products to the order and proceed to the cart.
- The order total should show no tax if the VAT number is valid and the customer is in a different country from your store’s base country.
- Enter an invalid VAT number. The order should still include tax, and the VAT number should appear highlighted in red.
Understanding the Tax Exemption Logic
The EU VAT Assistant plugin follows these rules:
| Condition | Tax Exemption Applied? |
|---|---|
| Customer country is different from shop base country | ✅ Yes (reverse charge) |
| Customer country is the same as shop base country and the setting “Remove VAT when customer is in base country” is enabled | ✅ Yes |
| Customer country is the same as shop base country and the setting is disabled | ❌ No |
| VAT number validation fails | ❌ No |
The code respects these rules exactly. You do not need to duplicate the logic; the snippet simply reads the setting from the EU VAT Assistant plugin.