Plugin Contributor
kluver
(@kluver)
Hi @jayem82,
That certainly is possible. 🙂
Add the following to your functions.php:
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_show_order_weight', 10, 2 );
function wpo_wcpdf_show_order_weight ($template_type, $order) { ?>
<tr class="order-weight">
<th>Total weight:</th>
<td>
<?php
$items = $order->get_items();
$total_weight = 0;
$extra_weight = 0.2;
foreach ($items as $item_id => $item) {
$quantity = $item->get_quantity();
if ( $product = $order->get_product_from_item( $item ) ) {
$weight = $product->get_weight();
$total_weight += ( $weight + $extra_weight ) * $quantity;
}
}
echo $total_weight . ' kg';
?>
</td>
</tr>
<?php }
With kind regards,
Michael
Thread Starter
Jimmy
(@jayem82)
Thank you Michael!
I’ve also created snippet for total order items quantity. Thought I’d share the action hook for that one here as well. It seems to be working, could you just confirm that I’ve done it right?
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_order_total_quantity', 10, 2 );
function wpo_wcpdf_order_total_quantity ($template_type, $order) { ?>
<tr class="order-quantity">
<th>Items:</th>
<td>
<?php
$items = $order->get_items();
if( sizeof( $items ) > 0 ) {
foreach( $items as $item ) {
$qty += 1 * $item['quantity'];
}
}
echo $qty;
?>
</td>
</tr>
<?php }
Plugin Contributor
Ewout
(@pomegranate)
Looks good to me Jimmy, well done 🙂
Ewout
Thread Starter
Jimmy
(@jayem82)
Thanks again for your support, cheers!