/**
* Aelia EU VAT Assistant for WooCommerce - Add an order note when a valid VAT number is stored with an order.
* NOTE
* This code runs when the order meta is saved at checkout. It won't add an order note when the meta is added
* to manual orders, or via code.
*
* 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_action('woocommerce_checkout_update_order_meta', function($order_id, $posted_data) {
$order = wc_get_order($order_id);
$vat_number = $order->get_meta('vat_number');
// Add an order note with the VAT number when the number is present and valid
if(!empty($vat_number) &&
($order->get_meta('_vat_number_validated') === 'valid')) {
$order->add_order_note('VAT Number: ' . $vat_number);
}
}, 99, 2);
Comments