如果产品在 WooCommerce 中的购物车中有 product-tag,则将文本附加到产品标题
Append text to product title if product has product-tag on cart in WooCommerce
如果产品具有特定标签,我正在尝试将文本附加到购物车中的 WooCommerce 产品标题。
这就是我的。我错了条件代码。
add_filter( 'woocommerce_cart_item_name', 'add_udstilling_below_cart_item_name', 10, 3);
function add_udstilling_below_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
echo $item_name . ' (test)';
}
我试过这样的事情:
if ( has_term( 'udstillingsmodel', 'product_tag' ) ) {
}
但我需要帮助才能让它与购物车中的产品一起使用。
function add_udstilling_below_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
$product_id = $cart_item['product_id'];
/* Uncomment for debug purposes
$terms = wp_get_post_terms( $product_id, 'product_tag' );
echo '<pre>', print_r($terms, 1), '</pre>';
*/
if ( has_term( 'udstillingsmodel', 'product_tag', $product_id ) ) {
$item_name = $item_name . ' (test)';
}
return $item_name;
}
add_filter( 'woocommerce_cart_item_name', 'add_udstilling_below_cart_item_name', 10, 3 );
如果产品具有特定标签,我正在尝试将文本附加到购物车中的 WooCommerce 产品标题。
这就是我的。我错了条件代码。
add_filter( 'woocommerce_cart_item_name', 'add_udstilling_below_cart_item_name', 10, 3);
function add_udstilling_below_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
echo $item_name . ' (test)';
}
我试过这样的事情:
if ( has_term( 'udstillingsmodel', 'product_tag' ) ) {
}
但我需要帮助才能让它与购物车中的产品一起使用。
function add_udstilling_below_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
$product_id = $cart_item['product_id'];
/* Uncomment for debug purposes
$terms = wp_get_post_terms( $product_id, 'product_tag' );
echo '<pre>', print_r($terms, 1), '</pre>';
*/
if ( has_term( 'udstillingsmodel', 'product_tag', $product_id ) ) {
$item_name = $item_name . ' (test)';
}
return $item_name;
}
add_filter( 'woocommerce_cart_item_name', 'add_udstilling_below_cart_item_name', 10, 3 );