این رو تست کنید
function itl_is_product_the_same_cat( $valid, $product_id, $quantity ) {
global $woocommerce;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
$terms = get_the_terms( $_product->id, 'product_cat' );
$target_terms = get_the_terms( $product_id, 'product_cat' ); // get the current items
foreach ( $terms as $term ) {
$cat_ids[] = $term->term_id; // get all the item categories in the cart
}
foreach ($target_terms as $term) {