Advertisement
businessdad

Add order note with VAT number on "save evidence" event

Apr 27th, 2020
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Aelia EU VAT Assistant for WooCommerce - Add an order note when a valid VAT number is stored with an order.
  3.  * NOTE
  4.  * This code runs every time the VAT evidence is saved against an order. It doesn't check if the order note was
  5.  * already added with the same VAT number. Using this code with the example at https://pastebin.com/Pa0LLiLh could
  6.  * result in the note being added multiple times.
  7.  *
  8.  * DISCLAIMER
  9.  * Because this code is free of charge, there is no warranty for it, to the extent permitted by applicable law.
  10.  * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
  11.  * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
  12.  * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
  13.  * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
  14.  *
  15.  * 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
  16.  * in relation to it. Should you need a consultation, or assistance to customise this code, you can contact us to avail
  17.  * of our paid consultation services: https://aelia.co/hire_us
  18.  */
  19. add_filter('wc_aelia_eu_vat_assistant_store_vat_evidence',  function($vat_evidence, $order) {
  20.   // Add an order note with the VAT number when the number is present and valid
  21.   if(!empty($vat_evidence['exemption']['vat_number']) &&
  22.      !empty($vat_evidence['exemption']['vat_number_validated']) &&
  23.      ($vat_evidence['exemption']['vat_number_validated'] === 'valid')) {
  24.     $order->add_order_note('VAT Number: ' . $vat_evidence['exemption']['vat_number']);
  25.   }
  26.   // Return the VAT evidence as is, we don't need to modify it
  27.   return $vat_evidence;
  28. }, 99, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement