admin管理员组文章数量:1130349
I want to check the product in cart from which category is and if is from Category X to show some message.
So far I've done this and I've placed it in checkout.php
$categories = array('cat' => '39');
foreach ( WC()->cart->get_cart() as $cart_item ) {
if ( has_term( $categories, 'product_cat', $cart_item['product_id'] ) ) {
$found = true; // Set to true
break; // Stop the loop
}
}
if ( $found ) {
do_action( 'woocommerce_cart_collaterals' );
}
else {
echo "Product from category X";
}
Sadly, here I see the else { echo "Product from category X"; } no matter if the product is from Category X or no.
var_dump($found); return NULL
I want to check the product in cart from which category is and if is from Category X to show some message.
So far I've done this and I've placed it in checkout.php
$categories = array('cat' => '39');
foreach ( WC()->cart->get_cart() as $cart_item ) {
if ( has_term( $categories, 'product_cat', $cart_item['product_id'] ) ) {
$found = true; // Set to true
break; // Stop the loop
}
}
if ( $found ) {
do_action( 'woocommerce_cart_collaterals' );
}
else {
echo "Product from category X";
}
Sadly, here I see the else { echo "Product from category X"; } no matter if the product is from Category X or no.
var_dump($found); return NULL
本文标签: wp queryCheck the product in the cart from which category is and show message
版权声明:本文标题:wp query - Check the product in the cart from which category is and show message 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749121212a2319038.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论