Allow only one product category in cart at once in Woocommerce
问题 How would I go about configuring the Woocommerce cart to only allow one product category type in it at a time? 回答1: The following code will allow adding to cart only items from one product category avoiding add to cart and displaying a custom notice: add_filter( 'woocommerce_add_to_cart_validation', 'only_one_product_category_allowed', 20, 3 ); function only_one_product_category_allowed( $passed, $product_id, $quantity) { // Getting the product categories term slugs in an array for the