如果产品具有特定标签,我会尝试将文本附加到购物车中的 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 );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)