在购物车和结帐页面上显示 Woocommerce 产品类别 [英] Display Woocommerce Product Category on cart and checkout page
问题描述
我正在尝试让产品类别显示在每个添加的产品的购物车和结帐页面上.
I'm trying to get the product category to display on the cart and checkout pages for each product added.
我的 php 知识非常有限,所以最简单的解释会很棒:)
My php knowledge is very limited so the most dumbed down explanation would be great :)
我查看了 woocommerce 文档,并在 Google 上搜索了 Genesis Connect 文档,但没有找到我要找的内容.
I've had a look at the woocommerce docs and googled for the genesis connect docs but I didnt find what I was looking for.
使用 Genesis Woocommerce Connect 和最新的 woocommerce 和 wordpress.
Using Genesis Woocommerce Connect and the latest woocommerce and wordpress.
不知道从这里去哪里.. :/
Not sure where to go from here.. :/
推荐答案
the woocommerce>templates>cart>cart.php 是购物车页面.在此,foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item )
循环显示您添加到购物车的产品.循环的变量 $product_id
具有您添加到购物车的每个产品的 ID.将此代码放入循环中
the woocommerce>templates>cart>cart.php is the cart page.In this,foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item )
loop display the products you added to the cart.Variable $product_id
of the loop have the id of each product you added the the cart.
Put this code inside the loop
$terms = get_the_terms( $product_id, 'product_cat' );
foreach ($terms as $term) {
$product_cat = $term->name;
}
echo $product_cat ;
它将显示类别.锻炼一下,让我知道:)
It will display the categories. Work out and let me know:)
这篇关于在购物车和结帐页面上显示 Woocommerce 产品类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!