• Resolved ABCwebsites

    (@abcwebsites)


    Would it be possible to indicate to customers that their VAT number cannot be validated through no fault of their own? I.e. tell them the remote server is busy or unavailable and they should go to the Contact page for help?

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

    (@daigo75)

    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.

    Hello Diego,

    Could you please explain where to put the code to get this error message?

    @webbus in the functions.php of your WP child theme

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Specific error message’ is closed to new replies.