在woocommerce 3的购物车页面上显示商品属性的变化 [英] Display product attributes for variations on cart page in woocommerce 3
本文介绍了在woocommerce 3的购物车页面上显示商品属性的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在购物车"页面上显示产品类别及其变化?
How do I display a product category and it's variations on the Cart page?
- 这是一个带有变化的可变产品.
- 包含用于变化的属性.
- 没有其他属性(未设置变体).
推荐答案
要显示变体的产品属性,有两种方法:
To display the product attributes for variations there is 2 ways:
为此查看相关答案:购物车商品中的商品变化属性在WooCommerce中的显示方式有所不同
要显示产品类别,可以使用以下挂钩函数:
To display the product category you could use this hooked function:
add_filter( 'woocommerce_cart_item_name', 'customizing_cart_item_data', 10, 3);
function customizing_cart_item_data( $item_name, $cart_item, $cart_item_key ) {
$term_names = array();
// Get product categories
$terms = wp_get_post_terms( $cart_item['product_id'], 'product_cat' );
if( count($terms) > 0 ){
foreach( $terms as $term ) $term_names[] = $term->name;
$item_name .= '<p class="item-category" style="margin:12px 0 0; font-size: .875em;">
<strong class="label">' . _n( 'Category', 'Categories', count($terms), 'woocommerce' ) . ': </strong>
<span class="values">' . implode( ', ', $term_names ) . '</span>
</p>';
}
return $item_name;
}
代码会出现在您活动的子主题(或主题)的function.php文件或任何插件文件中.
经过测试,可以正常工作.
Tested and works.
这篇关于在woocommerce 3的购物车页面上显示商品属性的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文