• Resolved freakency

    (@freakency)


    Adding variables to packing slip. With new Brexit rules we need price on the packing slip. There is no tick box for this. I have used code very similar to below in functions to pump out a custom variable and it works fine.
    Indeed I can pump out a number of variables using this method but not order total or postage total.

    I want order total and order postage. Here is what i am trying to add:

    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_delivery_date2', 10, 2 );
    function wpo_wcpdf_delivery_date2 ($template_type, $order) {
        if ($template_type == 'packing-slip') {
            $document = wcpdf_get_document( $template_type, $order );
            ?>      
            <tr class="_order_total">
                <th>Order Total:</th>
                <td><?php $document->custom_field('_order_total'); ?></td>
            </tr>
            <?php
        }
    }

    Do i need to form the variable differently in php?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    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.

    Thread Starter freakency

    (@freakency)

    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.

    Thread Starter freakency

    (@freakency)

    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>
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘adding total to packing slip’ is closed to new replies.