Woocommerce:在购物车页面上显示产品重量 [英] Woocommerce: Displaying product weight on cart page

查看:32
本文介绍了Woocommerce:在购物车页面上显示产品重量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在购物车页面显示产品重量:

I want to display product weight on cart page:

我已经走了这么远:

<td class="product-weight">
   <?php
     echo apply_filters( 'woocommerce_cart_item_weight', WC()->cart->cart_contents_weight);
   ?>
 </td><!-- /.product-weight -->

这段代码将显示购物车的总重量,但我想要单个产品的重量.

This piece of code will display the total weight of cart but I want weight of individual product.

任何帮助将不胜感激.参考网址:链接 [请添加几个产品]

Any help would be appreciated. Reference URL: Link [plz add few products]

推荐答案

试试这个:

global $woocommerce;

if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
    foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values )
    {
        $_product = $values['data'];
        $weight = $_product->weight; echo $weight;
    }
}

<td class="product-weight">
<?php
     echo apply_filters( 'woocommerce_cart_item_weight', $_product->get_weight());
?>
</td><!-- /.product-weight -->

这篇关于Woocommerce:在购物车页面上显示产品重量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆