Hi @freakency,
The packing slips don’t normally have access to the totals, so you’d need to create a custom template. From the invoice file, this is the relevant section you’d want to insert:
<td class="no-borders" colspan="2">
<table class="totals">
<tfoot>
<?php foreach( $this->get_woocommerce_totals() as $key => $total ) : ?>
<tr class="<?php echo $key; ?>">
<th class="description"><?php echo $total['label']; ?></th>
<td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
</tr>
<?php endforeach; ?>
</tfoot>
</table>
</td>
The easier way to go about this would be to use the Premium Extension, as the Customizer it offers would allow you to insert the “totals” block.
i did try the template method but then realised i had a function in functions that already injected variables in. Happy to use the template in child theme option.
I have reset up the template method and have it selecting my template correctly.
However when i add the above code it errors in nearly all places i try and add it except adding it to line 83. This is really close to what we want. it does add the total but it messes up the formatting of the rest of the list. Here is where i have added it in context:
`<table class=”order-details”>
<thead>
<tr>
<th class=”product”><?php _e(‘Product’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></th>
<th class=”quantity”><?php _e(‘Quantity’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></th>
</tr>
<td class=”no-borders” colspan=”2″>
<table class=”totals”>
<tfoot>
<?php foreach( $this->get_woocommerce_totals() as $key => $total ) : ?>
<tr class=”<?php echo $key; ?>”>
<th class=”description”><?php echo $total[‘label’]; ?></th>
<td class=”price”><span class=”totals-price”><?php echo $total[‘value’]; ?></span></td>
</tr>
<?php endforeach; ?>
</tfoot>
</table>
</td>
</thead>
I am guessing i have added it on a wrong line, but all other lines i have tried so far give me an error. e.g :
insert in line 84 i get this error: DOMPDF Exception: Frame not found in cellmap
insert in line 123 i get this error: Fatal error: Call to a member function get_cellmap() on null
Only adding it on line 83 does it at least not error. What line should i add it to, to not break the formatting of the rest of the order table?
many thanks for your time on this.
Ah you stick it at the bottom of the table like this:
This works perfectly.
Thank you for the code!
<table class="order-details">
<thead>
<tr>
<th class="product"><?php _e('Product', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
<th class="quantity"><?php _e('Quantity', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
</tr>
</thead>
<tbody>
<?php $items = $this->get_order_items(); if( sizeof( $items ) > 0 ) : foreach( $items as $item_id => $item ) : ?>
<tr class="<?php echo apply_filters( 'wpo_wcpdf_item_row_class', $item_id, $this->type, $this->order, $item_id ); ?>">
<td class="product">
<?php $description_label = __( 'Description', 'woocommerce-pdf-invoices-packing-slips' ); // registering alternate label translation ?>
<span class="item-name"><?php echo $item['name']; ?></span>
<?php do_action( 'wpo_wcpdf_before_item_meta', $this->type, $item, $this->order ); ?>
<span class="item-meta"><?php echo $item['meta']; ?></span>
<dl class="meta">
<?php $description_label = __( 'SKU', 'woocommerce-pdf-invoices-packing-slips' ); // registering alternate label translation ?>
<?php if( !empty( $item['sku'] ) ) : ?><dt class="sku"><?php _e( 'SKU:', 'woocommerce-pdf-invoices-packing-slips' ); ?></dt><dd class="sku"><?php echo $item['sku']; ?></dd><?php endif; ?>
<?php if( !empty( $item['weight'] ) ) : ?><dt class="weight"><?php _e( 'Weight:', 'woocommerce-pdf-invoices-packing-slips' ); ?></dt><dd class="weight"><?php echo $item['weight']; ?><?php echo get_option('woocommerce_weight_unit'); ?></dd><?php endif; ?>
</dl>
<?php do_action( 'wpo_wcpdf_after_item_meta', $this->type, $item, $this->order ); ?>
</td>
<td class="quantity"><?php echo $item['quantity']; ?></td>
</tr>
<td class="no-borders" colspan="2">
<table class="totals">
<tfoot>
<?php foreach( $this->get_woocommerce_totals() as $key => $total ) : ?>
<tr class="<?php echo $key; ?>">
<th class="description"><?php echo $total['label']; ?></th>
<td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
</tr>
<?php endforeach; ?>
</tfoot>
</table>
</td>
<?php endforeach; endif; ?>
</tbody>
</table>