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

    (@pomegranate)

    Hi! Yes that’s possible, but you will need to create a custom template for that purpose.
    Then after the items loop /before the end of tbody(here), insert the new rows.

    Snippets to get the total quantity and total weight:

    <?php
    // calculate total weight & total qty
    $order_weight = 0;
    $order_total_qty = 0;
    if( sizeof( $items ) > 0 ) {
        foreach( $items as $item ) {
            $order_total_qty += $item['qty']
            $product = $wpo_wcpdf->export->order->get_product_from_item( $item );
            if ( $product ) {
                $order_weight += $product->get_weight() * $item['qty'];
            }
        }
    }
    ?>
    
    Weight: <?php echo $order_weight; ?>
    Quantity: <?php echo $order_total_qty; ?>

    Hope that helps!
    Ewout

    @ewout

    Unfortunately I cannot get the code above to work in a custom template, when I run the PDF template it gives me a 500 error. Not too sure why

    Plugin Contributor Ewout

    (@pomegranate)

    David,
    There’s a semicolon missing in the code (after $order_total_qty += $item['qty']), this should work though:

    <?php
    // calculate total weight & total qty
    $order_weight = 0;
    $order_total_qty = 0;
    $items = $this->order->get_items();
    if( sizeof( $items ) > 0 ) {
        foreach( $items as $item ) {
            $order_total_qty += $item['qty'];
            $product = $wpo_wcpdf->export->order->get_product_from_item( $item );
            if ( $product ) {
                $order_weight += $product->get_weight() * $item['qty'];
            }
        }
    }
    ?>
    
    Weight: <?php echo $order_weight; ?><br/>
    Quantity: <?php echo $order_total_qty; ?>

    Ah darnit! I should have caught that ??

    No longer getting a 500 error, but both variables always echo “0”

    Plugin Contributor Ewout

    (@pomegranate)

    My bad – I’m on the road and wanted to give you a quick fix but I guess I shouldn’t do that. I’ve edited my previous post to avoid confusion for anyone else reading this. I’m 99.9% sure it works now. (it was reusing the $items from the order items table which is different from the original WC $items).

    Ewout

    Ewout, No problem! The edit you made works perfectly, thanks so much

    I was pulling my hair out trying to figure out how to display this data last week so your help is much appreciated

    Plugin Contributor Ewout

    (@pomegranate)

    Great, glad to hear it’s fixed now! I can recommend turning on debug logging in WordPress so you can find out the actual errors behind 500 internal server errors.

    Have a great weekend!

    Hi
    I don’t wish to hijack this thread but I have tried to follow this and no matter what I get a 500 error.
    As soon as I echo weight and qty it fails.
    Debug shows this:
    [03-Aug-2016 21:35:24 UTC] PHP Fatal error: Call to undefined method DOMText::getAttribute() in /home/chestnut/public_html/wp/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/lib/dompdf/include/cellmap.cls.php on line 437

    I have tried both invoice and slip in my custom templatebut neither example work.
    Latest wordpress, woocommerce and your plugin.

    All I’m trying to get is the total weight of an order.
    I look forward to hearing back if you can assist.
    Cheers.

    Hi figured it out.
    Had to set upa new tr and td with the classes to get it to work.
    Cheers

    Plugin Contributor Ewout

    (@pomegranate)

    Ah yes, the example wasn’t meant for output in a table, so that makes sense. DOMPDF is very picky about HTML in tables.

    Glad to hear that you managed to find the issue ??

    Have a fantastic day!
    Ewout

    And you, cheers.
    If it helps anyone…

    <?php
    		// calculate total weight & total qty
    		$order_weight = 0;
    		$order_total_qty = 0;
    		$items = $this->order->get_items();
    		if( sizeof( $items ) > 0 ) {
    		    foreach( $items as $item ) {
    		        $order_total_qty += $item['qty'];
    		        $product = $wpo_wcpdf->export->order->get_product_from_item( $item );
    		        if ( $product ) {
    		            $order_weight += $product->get_weight() * $item['qty'];
    		        }
    		    }
    		}
    		?>
    				<tr class="<?php echo apply_filters( 'wpo_wcpdf_item_row_class', $item_id, $wpo_wcpdf->export->template_type, $wpo_wcpdf->export->order, $item_id ); ?>">
    			<td class="product">Weight: <?php echo $order_weight; ?> <?php echo get_option('woocommerce_weight_unit'); ?><br/>
    </td><td class="quantity">Total <?php echo $order_total_qty; ?> items</td>
    		</tr>

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Add total number of products and total weight’ is closed to new replies.