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