• Resolved wendytgore

    (@wendytgore)


    Hello,
    How do I add the total weight to the packing slip?
    Thank you,
    Wendy

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

    (@pomegranate)

    Hi! There are two ways to do this.
    If you don’t mind a little custom coding, check the instructions here. If you prefer a simpler solution, the Premium Templates extension lets you add the total weight directly in the settings via the Customizer (either in the Totals section, or with a custom block using the {{order_weight}} placeholder).

    Hope that helps!
    Ewout

    Thread Starter wendytgore

    (@wendytgore)

    Thank you for your response. Have a placed this correctly?

    <?php do_action( ‘wpo_wcpdf_before_document’, $this->type, $this->order ); ?>

    <table class=”head container”>
    <tr>
    <td class=”header”>
    <?php
    if( $this->has_header_logo() ) {
    $this->header_logo();
    } else {
    echo apply_filters( ‘wpo_wcpdf_packing_slip_title’, __( ‘Packing Slip’, ‘woocommerce-pdf-invoices-packing-slips’ ) );
    }
    ?>
    </td>
    <td class=”shop-info”>
    <div class=”shop-name”><h3><?php $this->shop_name(); ?></h3></div>
    <div class=”shop-address”><?php $this->shop_address(); ?></div>
    </td>
    </tr>
    </table>

    <h1 class=”document-type-label”>
    <?php if( $this->has_header_logo() ) echo apply_filters( ‘wpo_wcpdf_packing_slip_title’, __( ‘Packing Slip’, ‘woocommerce-pdf-invoices-packing-slips’ ) ); ?>
    </h1>

    <?php do_action( ‘wpo_wcpdf_after_document_label’, $this->type, $this->order ); ?>

    <table class=”order-data-addresses”>
    <tr>
    <td class=”address shipping-address”>
    <!– <h3><?php _e( ‘Shipping Address:’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></h3> –>
    <?php $this->shipping_address(); ?>
    <?php if ( isset($this->settings[‘display_email’]) ) { ?>
    <div class=”billing-email”><?php $this->billing_email(); ?></div>
    <?php } ?>
    <?php if ( isset($this->settings[‘display_phone’]) ) { ?>
    <div class=”billing-phone”><?php $this->billing_phone(); ?></div>
    <?php } ?>
    </td>
    <td class=”address billing-address”>
    <?php if ( isset($this->settings[‘display_billing_address’]) && $this->ships_to_different_address()) { ?>
    <h3><?php _e( ‘Billing Address:’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></h3>
    <?php $this->billing_address(); ?>
    <?php } ?>
    </td>
    <td class=”order-data”>
    <table>
    <?php do_action( ‘wpo_wcpdf_before_order_data’, $this->type, $this->order ); ?>
    <tr class=”order-number”>
    <th><?php _e( ‘Order Number:’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></th>
    <td><?php $this->order_number(); ?></td>
    </tr>
    <tr class=”order-date”>
    <th><?php _e( ‘Order Date:’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></th>
    <td><?php $this->order_date(); ?></td>
    </tr>
    <tr class=”shipping-method”>
    <th><?php _e( ‘Shipping Method:’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></th>
    <td><?php $this->shipping_method(); ?></td>
    </tr>
    <?php do_action( ‘wpo_wcpdf_after_order_data’, $this->type, $this->order ); ?>
    </table>
    </td>
    </tr>
    </table>

    <?php do_action( ‘wpo_wcpdf_before_order_details’, $this->type, $this->order ); ?>

    <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>
    <?php endforeach; endif; ?>
    <?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; ?> </tbody>
    </table>

    <?php do_action( ‘wpo_wcpdf_after_order_details’, $this->type, $this->order ); ?>

    <?php do_action( ‘wpo_wcpdf_before_customer_notes’, $this->type, $this->order ); ?>
    <div class=”customer-notes”>
    <?php if ( $this->get_shipping_notes() ) : ?>
    <h3><?php _e( ‘Customer Notes’, ‘woocommerce-pdf-invoices-packing-slips’ ); ?></h3>
    <?php $this->shipping_notes(); ?>
    <?php endif; ?>
    </div>
    <?php do_action( ‘wpo_wcpdf_after_customer_notes’, $this->type, $this->order ); ?>

    <?php if ( $this->get_footer() ): ?>
    <div id=”footer”>
    <?php $this->footer(); ?>
    </div><!– #letter-footer –>
    <?php endif; ?>

    <?php do_action( ‘wpo_wcpdf_after_document’, $this->type, $this->order ); ?>

    Thread Starter wendytgore

    (@wendytgore)

    I have followed the instructions, but have not been able to get the total weight to show. Please advise.

    Plugin Contributor Ewout

    (@pomegranate)

    Hi! you placed the snippet inside the order details table, which breaks the layout. If you put it after the </table> tag, it should work. Here’s an update for the code so that it’s also fully compatible with PDF Invoices 2.X:

    
    <?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'];
            if ( $product = $this->order->get_product_from_item( $item ) ) {
                $order_weight += $product->get_weight() * $item['qty'];
            }
        }
    }
    ?>
    
    Weight: <?php echo $order_weight; ?><br/>
    Quantity: <?php echo $order_total_qty; ?>
    

    You can also use a PDF action hook instead, so that you don’t have to worry about the template getting out of date.

    
    add_action( 'wpo_wcpdf_after_order_details', 'wpo_wcpdf_order_weight', 10, 2 );
    function wpo_wcpdf_order_weight( $document_type, $order ) {
        if ($document_type == 'packing-slip') {
            // calculate total weight & total qty
            $order_weight = 0;
            $order_total_qty = 0;
            $items = $order->get_items();
            if( sizeof( $items ) > 0 ) {
                foreach( $items as $item ) {
                    $order_total_qty += $item['qty'];
                    if ( $product = $order->get_product_from_item( $item ) ) {
                        $order_weight += $product->get_weight() * $item['qty'];
                    }
                }
            }
            ?>
            Weight: <?php echo $order_weight; ?><br/>
            Quantity: <?php echo $order_total_qty; ?>
            <?php
        }
    }
    

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    If you need more help with this, I recommend finding a coder to help with this or getting the Premium Templates as Michael suggested. We can only offer limited support for customizations if you are using the free version.

    Hope that helps!
    Ewout

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do I add the total weight to the packing slip?’ is closed to new replies.