At the moment, the EU VAT Assistant doesn’t have a user interface to configure custom error messages, but you can display one by implementing a filter for hook wc_aelia_eu_vat_assistant_customer_vat_exemption
. Here’s a template, to get you started:
/**
* Shows a custom error message when a VAT number could not be validated.
*/
function show_custom_vat_error_messages() {
// Use a hook for "wc_aelia_eu_vat_assistant_customer_vat_exemption" to check if a
// VAT number could not be validated, and show a custom error message if that's the case
add_filter('wc_aelia_eu_vat_assistant_customer_vat_exemption', function($customer_is_vat_exempt, $vat_country, $vat_number, $vat_number_validated, $raw_vat_validation_response) {
if($vat_number_validated === 'could-not-be-validated') {
wc_add_notice('Sorry, we could not validate your VAT number.', 'error');
}
return $customer_is_vat_exempt;
}, 10, 5);
}
// Hook into the checkout process to show a custom error message when
// the VAT number can't be validated
add_action('woocommerce_checkout_process', 'show_custom_vat_error_messages');
This will show a custom error message when the customer tries to complete the checkout and the VAT number can’t be validated. If you would like to show that message every time the validation fails (i.e. not just during the final checkout step), you can just use the code for the add_filter()
call, without wrapping it into the show_custom_vat_error_messages
function.
Please note that this 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.