• Resolved underwd

    (@underwd)


    Scenario:

    Customer orders 10 widgets. Later requests a refund for 5, which is accomplished through the backend. Subsequently generating a packing slip still shows the original 10 widgets ordered.

    I know there are requests out there to update the pdf invoice after refunds, and by design you don’t because it’s apparently illegal in some countries, but a packing slip is different.

    Great plugin. Thank you.

    https://www.ads-software.com/plugins/woocommerce-pdf-invoices-packing-slips/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! I agree, packing slips do not fall under this rule, but since refund support comes as a package, I have not included this in the free version. In the Professional extension, this is a simple setting.

    You can achieve the same thing in the free version with a filter:

    add_filter( 'wpo_wcpdf_order_items_data', 'wpo_wcpdf_subtract_refunded_qty', 10, 2 );
    function wpo_wcpdf_subtract_refunded_qty ( $items_data, $order ) {
        global $wpo_wcpdf;
        if ( $wpo_wcpdf->export->template_type == 'packing-slip' ) {
    
            foreach ($items_data as $key => &$item) {
                // item_id is required! (introduced in 1.5.3 of main plugin)
                if ( isset( $item['item_id'] ) ) {
                    $refunded_qty = $order->get_qty_refunded_for_item( $item['item_id'] );
                    $item['quantity'] = $item['quantity'] - $refunded_qty;
                }
    
                if ( $item['quantity'] == 0 ) {
                    //remove 0 qty items
                    unset( $items_data[$key] );
                }
            }
        }
        return $items_data;
    }

    Hope that helps!
    Ewout

    Thread Starter underwd

    (@underwd)

    Wow. That is incredible responsiveness. Thank you!

    Thread Starter underwd

    (@underwd)

    Just as an FYI, since your solution you posted above about a year ago, it looks like perhaps Woocommerce is changing the way it stores the integer for refunded quantities.

    I began noticing that, for example, if a customer bought 2 items and returned 1, the total quantity being shown on PDF invoices and packing slips using the filter above was 3, not 1, as expected.

    If I change the line above to (changing sign of operand):
    $item['quantity'] = $item['quantity'] + $refunded_qty;
    then the math is correct.

    So maybe previously WC stored a refunded qty as +1 and now it’s stored as -1. Not sure.

    Plugin Contributor Ewout

    (@pomegranate)

    That’s entirely correct. This was changed in WooCommerce 2.6. Let’s hope it will stay like this from now on ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Quantities in packing slip not right after refund’ is closed to new replies.