Код: Выделить всё
add_action( 'woocommerce_check_cart_items','prevent_multiple_category');
function prevent_multiple_category() {
$disallowed_categories = array( 'pickup', 'ship' );
$both_categories_in_cart = false;
$cart_items = WC()->cart->get_cart();
foreach ( $cart_items as $cart_item ) {
$product_id = $cart_item['product_id'];
$product_categories = get_the_terms( $product_id, 'product_cat' );
$product_categories_slugs = array_map( function( $term ) {
return $term->slug;
}, $product_categories );
$intersect = array_intersect( $product_categories_slugs, $disallowed_categories );
if ( ! empty( $intersect ) ) {
if ( $both_categories_in_cart ) {
//$woocommerce->cart->empty_cart();
wc_add_notice( __( 'You can not add Pickup Products and Shipping Products in the cart together.', 'text-domain' ), 'error' );
WC()->cart->empty_cart();
add_filter('woocommerce_cart_item_removed_notice_type', '__return_null');
break;
} else {
$both_categories_in_cart = true;
}
}
}
}
Помощь, пожалуйста?
Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/792 ... o-the-cart
Мобильная версия