• Plugin Author Diego

    (@daigo75)


    Orders created or modified manually are outside the scope of the EU VAT MOSS rules, for which the EU VAT Assistant was designed. Due to that, the EU VAT Assistant doesn’t perform VAT number validations, nor it applies exemptions on such orders.

    It’s still possible to mark an order as “VAT exempt” by adding to it a custom meta called is_vat_exempt with a value of yes. When the “Recalculate” button is clicked, WooCommerce reads that meta and make the order exempt from taxes.

    Please just be aware that this won’t trigger the validation of the VAT number, and won’t add VAT exemption details to the order meta.

    It’s possible to validate a VAT number using custom code, by calling filter wc_aelia_eu_vat_assistant_validate_vat_number. Here’s an example of how to call that filter:

    $validation_result = apply_filters('wc_aelia_eu_vat_assistant_validate_vat_number', $validation_result, $country, $vat_number, true);

    This will return the raw validation response from the VIES service, which can be checked to verify if the number is valid. You can then store the response and the VAT data against the order, updating the one previously stored by the EU VAT Assistant.

    How to validate a VAT number and update the VAT data on an existing order
    At the moment, there isn’t a ready-made function to validate a VAT number and update the VAT data on an existing order. As explained, orders created or modified manually fall outside the scope of VAT MOSS, therefore we didn’t implement a feature to cover that aspect (you’re welcome to sponsor its implementation).

    It’s possible to use some custom code to perform such operation, by following the same steps performed in method WC_Aelia_EU_VAT_Assistant::save_eu_vat_data(). The code below shows an example of how that can be done. Please read the code and its disclaimer notes carefully, before implementing it.

    
    /**
     * Aelia EU VAT Assistant for WooCommerce - Validate VAT number and store VAT information against
     * an existing order.
     * 
     * HOW TO USE THIS CODE
     * This code shows how to use the EU VAT Assistant to call the VIES service to validate a EU VAT number
     * and how to store or update the VAT information collected during that process. You can wrap this code 
     * in a plugin, and wrap it into a function, then call it on Ajax events such as "wp_ajax_woocommerce_calc_line_taxes"
     * or "wp_ajax_collect_order_vat_info". 
     * Note: when linking the execution of the code to the Ajax event, you should use a high priority (e.g. 1), so that
     * your custom code runs before the "standard" one. This is important because, normally, Ajax handler terminate the
     * script after running, and that would prevent your code from being executed.
     * 
     * @see WC_AJAX::calc_line_taxes()
     * @see Aelia\WC\EU_VAT_Assistant\WC_Aelia_EU_VAT_Assistant::wp_ajax_collect_order_vat_info()
     * 
     * IMPORTANT
     * This code will not remove VAT from an existing order that had taxes added to it, nor will it refund
     * VAT that has already been paid. If a customer placed an order and paid VAT, e.g. because they forgot,
     * to enter their VAT number, or because their numbe, you will have to refund such VAT manually. We recommend
     * to consult your tax advisor to discuss the best way to handle this process, in compliance with your local
     * tax laws. 
     * 
     * DISCLAIMER
     * THE USE OF THIS CODE IS AT YOUR OWN RISK. You remain fully liable for compliance with tax laws.
     * This code is offered free of charge and there is no warranty for it, to the extent permitted by applicable law.
     * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
     * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
     * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
     * is with you. Should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
     *
     * The code is provided as an example and it's not covered by our support service. We won't be able to offer free support
     * in relation to it. Should you need a consultation, or assistance to customise this code, you can contact us to avail
     * of our paid consultation services: https://aelia.co/hire_us
     */
    
    // Replace "123" with the ID of an actual order
    $order = new  Aelia\WC\EU_VAT_Assistant\Order(123);
    
    // Call the VAT validation function. This call assumes that the order
    // already has a VAT number stored in its "vat_number" meta
    $raw_vies_response = apply_filters('wc_aelia_eu_vat_assistant_validate_vat_number', null, $order->get_billing_country(), $order->get_meta('vat_number'), true);
    
    if(!empty($raw_vies_response)) {
      // Extract the VAT validation
      $vat_number_validated = $raw_vies_response['euva_validation_result'];
      $order->update_meta_data('_vat_number_validated', $vat_number_validated);
    
      // Store the VIES response against the order
      $order->update_meta_data('vies_response', $raw_vies_response);
    
      if(is_array($raw_vies_response) && isset($raw_vies_response['raw_response']) && is_array($raw_vies_response['raw_response'])) {
        // Change all the keys in the response to lower-case. This is to avoid issues with keys being
        // returned like "requestIdentifier", "RequestIdentifier", "requestidentifier" by different versions
        // of the VIES service
        $raw_vies_response['raw_response'] = array_change_key_case($raw_vies_response['raw_response'], CASE_LOWER);
      }
    
      // Store the consultation number, if present
      if(!empty($raw_vies_response['raw_response']['requestidentifier'])) {
        $order->update_meta_data('vies_consultation_number', $raw_vies_response['raw_response']['requestidentifier']);
      }
      else {
        $order->update_meta_data('vies_consultation_number', __('Not returned', self::$text_domain));
      }
      $order->save_meta_data();
    
      // Generate and store details about order VAT
      $order->update_vat_data();
      // Save EU VAT compliance evidence
      $order->store_vat_evidence();
    }
    

    A copy of the same code can be found here (it may be a bit easier to read): https://pastebin.com/SHHJjD9Z.

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

    (@daigo75)

    Correction
    Line $order->update_meta_data('vies_consultation_number', __('Not returned', self::$text_domain)); contains an invalid reference to self::$text_domain. Please replace that text with your text domain. Example:
    $order->update_meta_data('vies_consultation_number', __('Not returned', 'your-text-domain'));

    Plugin Author Diego

    (@daigo75)

    Further update – 26 June 2020
    The validation of the VAT number on manual orders has been added to the feature requests for the EU VAT Assistant, so that it can be implemented in a future update.

    Plugin Author Diego

    (@daigo75)

    Update – 29 June 2020
    The validation of the VAT number on manual orders has been added to the EU VAT assistant in version 1.14.2.200629. The custom code described in this thread is no longer needed.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘FAQ – VAT exemption on orders created manually [Jun 2020]’ is closed to new replies.