Advertisement
businessdad

Add order note with VAT number at checkout

Apr 27th, 2020
458
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 when the order meta is saved at checkout. It won't add an order note when the meta is added
  5.  * to manual orders, or via code.
  6.  *
  7.  * DISCLAIMER
  8.  * Because this code is free of charge, there is no warranty for it, to the extent permitted by applicable law.
  9.  * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
  10.  * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
  11.  * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
  12.  * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
  13.  *
  14.  * 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
  15.  * in relation to it. Should you need a consultation, or assistance to customise this code, you can contact us to avail
  16.  * of our paid consultation services: https://aelia.co/hire_us
  17.  */
  18. add_action('woocommerce_checkout_update_order_meta', function($order_id, $posted_data) {
  19.   $order = wc_get_order($order_id);
  20.   $vat_number = $order->get_meta('vat_number');
  21.  
  22.   // Add an order note with the VAT number when the number is present and valid
  23.   if(!empty($vat_number) &&
  24.      ($order->get_meta('_vat_number_validated') === 'valid')) {
  25.     $order->add_order_note('VAT Number: ' . $vat_number);
  26.   }
  27. }, 99, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement