SHOW:
|
|
- or go back to the newest paste.
| 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 |
| 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 | - | * already added with the same VAT number. Using this code with the example at https://pastebin.com/Pa0LLiLh could |
| 5 | + | * to manual orders, or via code. |
| 6 | - | * result in the note being added multiple times. |
| 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 | - | add_filter('wc_aelia_eu_vat_assistant_store_vat_evidence', function($vat_evidence, $order) {
|
| 19 | + | $order = wc_get_order($order_id); |
| 20 | $vat_number = $order->get_meta('vat_number');
| |
| 21 | - | if(!empty($vat_evidence['exemption']['vat_number']) && |
| 21 | + | |
| 22 | - | !empty($vat_evidence['exemption']['vat_number_validated']) && |
| 22 | + | |
| 23 | - | ($vat_evidence['exemption']['vat_number_validated'] === 'valid')) {
|
| 23 | + | if(!empty($vat_number) && |
| 24 | - | $order->add_order_note('VAT Number: ' . $vat_evidence['exemption']['vat_number']);
|
| 24 | + | ($order->get_meta('_vat_number_validated') === 'valid')) {
|
| 25 | $order->add_order_note('VAT Number: ' . $vat_number);
| |
| 26 | - | // Return the VAT evidence as is, we don't need to modify it |
| 26 | + | |
| 27 | - | return $vat_evidence; |
| 27 | + |