businessdad icon

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

businessdad | PRO | 04/27/20 07:26:58 PM UTC | 0 ⭐ | 1276 👁️ | Never ⏰ | []
PHP |

1.86 KB

|

None

|

0 👍

/

0 👎

/**
 * Aelia EU VAT Assistant for WooCommerce - Add an order note when a valid VAT number is stored with an order.
 * NOTE
 * This code runs every time the VAT evidence is saved against an order. It doesn't check if the order note was
 * already added with the same VAT number. Using this code with the example at https://pastebin.com/Pa0LLiLh could
 * result in the note being added multiple times.
 *
 * DISCLAIMER
 * Because this code is free of charge, 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
 */
add_filter('wc_aelia_eu_vat_assistant_store_vat_evidence',  function($vat_evidence, $order) {
  // Add an order note with the VAT number when the number is present and valid
  if(!empty($vat_evidence['exemption']['vat_number']) &&
     !empty($vat_evidence['exemption']['vat_number_validated']) &&
     ($vat_evidence['exemption']['vat_number_validated'] === 'valid')) {
    $order->add_order_note('VAT Number: ' . $vat_evidence['exemption']['vat_number']);
  }
  // Return the VAT evidence as is, we don't need to modify it
  return $vat_evidence;
}, 99, 2);

Comments