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