Quantcast
Channel: Topic Tag: action | WordPress.org
Viewing all articles
Browse latest Browse all 889

WooCommerce only one product in cart for specific category

$
0
0

Hi there,

suppose I have 2 categories in my shop (category A and category B): when a product from category A is added to the shopping cart, no further product from category A and category B should be added. However, category B should be able to add as many products as the customer wants (except category A).

– Category A: Maximum one product of category A, nothing else
– Category B: No limit (but not B and A at the same time)

After some research I found the following hook, which generally only allows one product in the shopping cart. Can someone help me with that? Hook for a product:


/**
 * @snippet       WooCommerce Max 1 Product @ Cart
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WC 3.7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
  
add_filter( 'woocommerce_add_to_cart_validation', 'bbloomer_only_one_in_cart', 99, 2 );
   
function bbloomer_only_one_in_cart( $passed, $added_product_id ) {
   wc_empty_cart();
   return $passed;
}

Viewing all articles
Browse latest Browse all 889

Trending Articles