Php Woocommerce:在页眉中添加购物车重量

Php Woocommerce:在页眉中添加购物车重量,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我想把购物车的重量加到购物车旁边的收割台上。只是购物车的总重量。我已经走了这么远: <tr class="total-weight"> <?php global $woocommerce; ?> <th><?php _e('Total Weight', 'woocommerce'); ?></strong></th> <td><span class="amount"><?php

我想把购物车的重量加到购物车旁边的收割台上。只是购物车的总重量。我已经走了这么远:

<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>


这段代码输出购物车的重量,但我不知道如何将其添加到标题中


任何帮助都将不胜感激

您可以将代码保存为函数,并在需要显示总重量的任何地方调用该函数。例如:

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
}
功能显示\u重量(){
?>


把它放在header.php文件中?啊哈,这不是那么容易,有一大堆文件,购物车、导航都是从这些文件中生成的。这不是那么简单。我指的是你主题本身的header.php文件。你想把它放在表内作为标题还是放在表外作为标题?嗨,Rohil,我只想把它插入标题中,表是不需要