WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce PDF Invoices & Packing Slips
[resolved] Total weight in packing slip (6 posts)

  1. endeavouren
    Member
    Posted 11 months ago #

    Hi, we have been modifying the packing slip and invoice for our needs. But we would like to add totalt weight on packing slip as well. As I can see I cannot find how to add this line to the packing slip. This would be a nice option to include to get the total weight to mangage deliver costs for example.

    Anyone?

    Cheers!

    https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/

  2. Ewout
    Member
    Plugin Author

    Posted 11 months ago #

    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

  3. endeavouren
    Member
    Posted 11 months ago #

    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!

  4. Ewout
    Member
    Plugin Author

    Posted 11 months ago #

    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;
    ?>
  5. endeavouren
    Member
    Posted 11 months ago #

    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!

  6. Ewout
    Member
    Plugin Author

    Posted 11 months ago #

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

Reply

You must log in to post.

About this Plugin

About this Topic