Woocommerce: Adding Cart weight in header

I would like to add cart weight to header beside the cart. Just the total weight of cart. I’ve come so far:

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

This code outputs the weight of cart but I’m unable to figure out how do I add it in the header.

Read More

any help would be greatly appreciate

Related posts

Leave a Reply

1 comment

  1. You could do save your code as a function and simply call that function wherever you need the total weight to show up. For example:

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