在Woocommerce中将产品描述添加到购物车中 [英] Add product description to cart items in Woocommerce
问题描述
我正在努力找到针对Woocommerce的单页签出插件的此问题的简单解决方案.
I'm struggling to find a simple solution to this problem I'm having with One-page-checkout plugin for Woocommerce.
我的客户想在购物车商品中的商品标题旁边添加商品说明.
关于如何操作代码以显示描述的任何想法?
My client would like to add the product description next to the product title in cart items.
Any thoughts on how I can manipulate the code to show the description?
这是我实际上拥有的:
我认为该插件只会将说明隐藏在某个地方,但我无法在代码中的任何位置找到它.
I would think that this plugin would just be hiding the description somewhere but I can't locate it anywhere in the code.
推荐答案
有2种方法(制作产品和产品变体):
There is 2 ways to do it (making work for products and product variations):
1).通过自定义功能连接到 woocommerce_get_item_data
动作挂钩 (最佳方法) :
1). With custom function hooked in woocommerce_get_item_data
action hook (The best way):
add_filter( 'woocommerce_get_item_data', 'customizing_cart_item_data', 10, 2 );
function customizing_cart_item_data( $cart_data, $cart_item ) {
$description = $cart_item['data']->get_description(); // Get the product description
// For product variations when description is empty
if( $cart_item['variation_id'] > 0 && empty( $description ) ){
// Get the parent variable product object
$parent_product = wc_get_product( $cart_item['product_id'] );
// Get the variable product description
$description = $parent_product->get_description();
}
// If product or variation description exists we display it
if( ! empty( $description ) ){
$cart_data[] = array(
'key' => __( 'Description', 'woocommerce' ),
'value' => $description,
'display' => $description,
);
}
return $cart_data;
}
代码会出现在您活动的子主题(或主题)的function.php文件或任何插件文件中.
…或…
2).将自定义功能连接到 woocommerce_cart_item_name
过滤器挂钩:
2). With custom function hooked in woocommerce_cart_item_name
filter hook:
这篇关于在Woocommerce中将产品描述添加到购物车中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!