Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor 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

    Thread Starter endeavouren

    (@endeavouren)

    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 Contributor 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;
    ?>
    Thread Starter endeavouren

    (@endeavouren)

    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 Contributor 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.