• I need the total cart weight to show up on the order emails so that the admin can easily find the total weight for the shipping company.

    I tried it with this code:

    <table>
    <tr class="total weight">
       <th><strong><?php _e('Total Weight', 'woocommerce'); ?></strong></th>
         <td><strong><?php
           $total_weight = $woocommerce->cart->cart_contents_weight;
           $total_weight .= ' '.get_option('woocommerce_weight_unit');
           echo $total_weight;
         ?></strong></td>
     </tr>
     </table>

    But in the email, nothing shows up after “Total Weight”.

    https://wordpress.org/plugins/woocommerce/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Try adding:

    global $woocommerce;

    before using the $woocommerce variable.

    Thread Starter indira14

    (@indira14)

    Hi lorro,

    I followed your suggestion. I changed the code in admin-new-order.php to

    <table>
    <tr class="total weight">
       <th><strong><?php _e('Total Weight', 'woocommerce'); ?></strong></th>
         <td><strong><?php
           global $woocommerce;
           $total_weight = $woocommerce->cart->cart_contents_weight;
           $total_weight .= ' '.get_option('woocommerce_weight_unit');
           echo $total_weight;
         ?></strong></td>
     </tr>
     </table>

    But it didn’t change anything. Still no number of the weight showing up in the emails.

    Works for me.

    I wonder where you are putting it in admin_new_order.php. In my test, I put it at line 45, after the line with the </table> tag.

    If you can find or add this line in wp_config.php
    define(‘WP_DEBUG’, false);
    and change false to true for testing, it may give a clue about what’s going wrong.

    Depending on your mail client, you can expose the email markup with control-F3, if so, look for any clues in the markup near “Total weight”.

    Thread Starter indira14

    (@indira14)

    This is my entire admin_new_order.php

    <?php
    /**
    * Admin new order email
    *
    * @author WooThemes
    * @package WooCommerce/Templates/Emails/HTML
    * @version 2.0.0
    */
    if ( ! defined( ‘ABSPATH’ ) ) exit; // Exit if accessed directly ?>

    <?php do_action( ‘woocommerce_email_header’, $email_heading ); ?>

    <p><?php printf( __( ‘You have received an order from %s. Their order is as follows:’, ‘woocommerce’ ), $order->billing_first_name . ‘ ‘ . $order->billing_last_name ); ?></p>

    <?php do_action( ‘woocommerce_email_before_order_table’, $order, true, false ); ?>

    <h2>id . ‘&action=edit’ ); ?>”><?php printf( __( ‘Order: %s’, ‘woocommerce’), $order->get_order_number() ); ?> (<?php printf( ‘<time datetime=”%s”>%s</time>’, date_i18n( ‘c’, strtotime( $order->order_date ) ), date_i18n( wc_date_format(), strtotime( $order->order_date ) ) ); ?>)</h2>

    <table cellspacing=”0″ cellpadding=”6″ style=”width: 100%; border: 1px solid #eee;” border=”1″ bordercolor=”#eee”>
    <thead>
    <tr>
    <th scope=”col” style=”text-align:left; border: 1px solid #eee;”><?php _e( ‘Product’, ‘woocommerce’ ); ?></th>
    <th scope=”col” style=”text-align:left; border: 1px solid #eee;”><?php _e( ‘Quantity’, ‘woocommerce’ ); ?></th>
    <th scope=”col” style=”text-align:left; border: 1px solid #eee;”><?php _e( ‘Price’, ‘woocommerce’ ); ?></th>
    </tr>
    </thead>
    <tbody>
    <?php echo $order->email_order_items_table( false, true ); ?>
    </tbody>
    <tfoot>
    <?php
    if ( $totals = $order->get_order_item_totals() ) {
    $i = 0;
    foreach ( $totals as $total ) {
    $i++;
    ?><tr>
    <th scope=”row” colspan=”2″ style=”text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo ‘border-top-width: 4px;’; ?>”><?php echo $total[‘label’]; ?></th>
    <td style=”text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo ‘border-top-width: 4px;’; ?>”><?php echo $total[‘value’]; ?></td>
    </tr><?php
    }
    }
    ?>
    </tfoot>
    </table>

    <table>
    <tr class=”total weight”>
    <th><?php _e(‘Total Weight’, ‘woocommerce’); ?></th>
    <td><?php
    global $woocommerce;
    $total_weight = $woocommerce->cart->cart_contents_weight;
    $total_weight .= ‘ ‘.get_option(‘woocommerce_weight_unit’);
    echo $total_weight;
    ?>
    </td>
    </tr>
    </table>

    <?php do_action( ‘woocommerce_email_after_order_table’, $order, true, false ); ?>

    <?php do_action( ‘woocommerce_email_order_meta’, $order, true, false ); ?>

    <h2><?php _e( ‘Customer details’, ‘woocommerce’ ); ?></h2>

    <?php if ( $order->billing_email ) : ?>
    <p><?php _e( ‘Email:’, ‘woocommerce’ ); ?> <?php echo $order->billing_email; ?></p>
    <?php endif; ?>
    <?php if ( $order->billing_phone ) : ?>
    <p><?php _e( ‘Tel:’, ‘woocommerce’ ); ?> <?php echo $order->billing_phone; ?></p>
    <?php endif; ?>

    <?php wc_get_template( ’emails/email-addresses.php’, array( ‘order’ => $order ) ); ?>

    <?php do_action( ‘woocommerce_email_footer’ ); ?>

    As far as I know I put it exactly where you said, line 45 right after </table>.

    Yes, the extra code is in the same place that I used.

    Your file has some characters missing at line 17. Though I don’t think that’s the problem, its probably best to start over with a fresh copy of admin-new-order.php.

    There are two versions of admin-new-order.php:
    woocommerce/templates/emails/admin-new-order.php
    for html emails, and
    woocommerce/templates/emails/plain/admin-new-order.php
    for plain text emails.

    The email type is set at Dashboard / WooCommerce / Settings / Emails tab, New Order section, Email type dropdown. Could you just check you are editing the version appropriate to the email type.

    Thread Starter indira14

    (@indira14)

    It worked, thanks so much!

    One thing: the weight shows 0kg if someone pays with iDeal. Any ideas on how to fix that?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Weight in email’ is closed to new replies.