In Woocommerce, I'm trying to make a function that displays a message above the cart page when products with both categories are in the cart.
I'm trying to modify code that I found here but now it already shows the message when one of the categories is added instead of both:
add_action( 'woocommerce_before_cart', 'allclean_add_checkout_content', 12 );
function allclean_add_checkout_content() {
$special_cat2 = 'test-cat2';
$special_cat3 = 'test-cat3';
$bool = false;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$item = $cart_item['data'];
if ( has_term( $special_cat2 && $special_cat3, 'product_cat', $item->id ) )
$bool = true;
}
if ($bool)
echo '<div class="cartmessage">Warning! Beware of combining these materials!</div>';
}