• Resolved mafcz

    (@mafcz)


    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)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hey @mafcz,

    > But the negative amount it is not applied for subtotal. Where is original price.
    I am not completely sure I understand what you need. ??

    It would be useful if you could explain using screenshots – of before vs after. ??
    See Uploading images to www.ads-software.com

    > But I need to reflect the subtotal with item that I add.
    How is it now? (screenshots)
    Is this an indication that maybe we need to better understand what WooCommerce considers to be a Subtotal..?

    • This reply was modified 7 months, 3 weeks ago by Darren Peyou.
    Thread Starter mafcz

    (@mafcz)

    My goal is to add another line to the invoice. This line is only added when a gift voucher is applied in the order. So the line has a negative cost. This was successful as seen in the invoice image.

    The problem is that the subtotal (in the “Medzisú?et” image) remains with the original value, as if the line with the negative amount was not added.

    The total is zero because the order is zero. This is because gift certificates are applied correctly otherwise.

    Thank you.

    Plugin Contributor dwpriv

    (@dwpriv)

    It seems as though you’re using a premium version of our plugin. Can you send us an email referencing this thread to [email protected], please? We’re not allow to discuss paid plugins on the forums

    Thread Starter mafcz

    (@mafcz)

    Ok, but this feature doesn’t have anyhthing to do with paid version. It is about using filter hook wpo_wcpdf_order_items_data which is in free version. I can disabale paid version a still do this thing…

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @mafcz,

    The case is that you are using the Premium Templates extension, and it manage the data differently. In addition, www.ads-software.com does not allow us to provide support to commercial products in these forums: https://www.ads-software.com/support/guidelines/#do-not-post-about-commercial-products

    Therefore, please contact us at [email protected], so we can continue with the help there. Please include your license key in your reply to provide help quicker.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add item to invoice with negative pricce’ is closed to new replies.