Add item to invoice with negative pricce
-
Hello, I trying to use filter hook wpo_wcpdf_order_items_data to add another another item to invocie if gift card is applied. And It works. But the negative amount it is not applied for subtotal. Where is original price.
The total amount is right because it is same as order. But I need to reflect the subtotal with iteam that i add.
Thanks.function custom_add_gift_card_item_to_pdf_invoice( $data_list, $order, $document_type ) { $gift_card_total = $order->get_meta( '_ywgc_applied_gift_cards_totals' ); $vatorder = (int)$order->get_total_tax() === 0 ? null : 20; if ( $gift_card_total ) { $gift_card_total_no_vat = $gift_card_total / (1 + ($vatorder / 100)); $gift_card_keys = array_keys($order->get_meta('_ywgc_applied_gift_cards', true) ?? []); $gift_card_data = array( 'name' => sprintf('Dar?ekovy kupón: %s', implode(', ', $gift_card_keys)), 'quantity' => 1, // Set the line total (=after discount) 'line_total' => '', 'single_line_total' => '', 'line_tax' => '', 'single_line_tax' => '', 'tax_rates' => sprintf('%d %%', $vatorder), 'calculated_tax_rates' => '', // Set the line subtotal (=before discount) 'line_subtotal' => wc_price($gift_card_total * -1), 'line_subtotal_tax' => '', 'ex_price' => wc_price($gift_card_total * -1), 'price' => wc_price($gift_card_total * -1), //$gift_card_total * -1, 'order_price' => wc_price($gift_card_total * -1), // Calculate the single price with the same rules as the formatted line subtotal (!) // = before discount 'ex_single_price' => wc_price($gift_card_total_no_vat * -1), 'single_price' => wc_price($gift_card_total * -1), ); $data_list[] = $gift_card_data; } return $data_list; } add_filter( 'wpo_wcpdf_order_items_data', 'custom_add_gift_card_item_to_pdf_invoice', 10, 3 );
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Add item to invoice with negative pricce’ is closed to new replies.