Support » Plugin: WooCommerce PDF Invoices & Packing Slips » Total weight in packing slip

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Ewout

    (@pomegranate)

    Hi,
    You need to loop through the order and calculate it manually, you could do that with the following code:

    <?php
    $items = $wpo_wcpdf->get_order_items();
    $weight = 0;
    if( sizeof( $items ) > 0 ) {
    	foreach( $items as $item ) {
    		$weight += $item['weight'];
    	}
    }
    echo $weight;
    ?>

    Let me know if you have any questions!

    Kind regards,
    Ewout

    Thanks!

    Seems to work good, just, it also needs to count the quantity of products, now it counts only 1 product of each.

    If I order ex. 40 pcs of a product that weigh 1kg each it should write 40kg instead of 1kg.

    How do I add this to this function?

    Thanks a lot!

    Cheers!

    Plugin Author Ewout

    (@pomegranate)

    Sorry, didn’t think of that 🙂

    <?php
    $items = $wpo_wcpdf->get_order_items();
    $weight = 0;
    if( sizeof( $items ) > 0 ) {
    	foreach( $items as $item ) {
    		$weight += $item['weight'] * $item['quantity'];
    	}
    }
    echo "Total weight: " . $weight;
    ?>

    Thanks, just small correction..

    quantity instead of qty, here is working code:

    <?php
    $items = $wpo_wcpdf->get_order_items();
    $weight = 0;
    if( sizeof( $items ) > 0 ) {
    	foreach( $items as $item ) {
    		$weight += $item['weight'] * $item['quantity'];
    	}
    }
    echo "Total weight: " . $weight;
    ?>

    Thanks for the help!
    Cheers!

    Plugin Author Ewout

    (@pomegranate)

    Yes, noticed that – I already edited my answer. Let me know if you have any other questions!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Total weight in packing slip’ is closed to new replies.