you mean if someone buy product 1 cant buy product 4 or product 10 ?Anyone know a way to restrict products from being sold with any other products?
More so, the product can only be purchased on it's own, its a sample product, so basically, if its in the cart, you can't add anything else to the cart.you mean if someone buy product 1 cant buy product 4 or product 10 ?
More so, the product can only be purchased on it's own, its a sample product, so basically, if its in the cart, you can't add anything else to the cart.
yep that's exactly the code i'm using right now![]()
Disable shopping when an item from a specific product category is in cart in Woocommerce
I am trying to Disable shopping if a an item from a specific product category is in cart (which is a subscription in form of product with tabs - checkout and shipping are stripped off). When that p...stackoverflow.com
Replace the first part of the code with this (tested and works):Trying to change the way it works where the restricted product doesn't get added rather than removing all other products.
add_filter( 'woocommerce_add_to_cart_validation', 'only_restricted_item_allowed', 10, 6 );
function only_restricted_item_allowed ( $passed, $product_id, $quantity ){
$category = 'restricted';
if ( ! WC()->cart->is_empty() && has_term( $category, 'product_cat', $product_id ) )
{
wc_add_notice( __('Sorry you can only order this sample product on its own.', 'woocommerce' ), 'error' );
return false;
}
return $passed;
}
which first part lolReplace the first part of the code with this (tested and works):
PHP:add_filter( 'woocommerce_add_to_cart_validation', 'only_restricted_item_allowed', 10, 6 ); function only_restricted_item_allowed ( $passed, $product_id, $quantity ){ $category = 'restricted'; if ( ! WC()->cart->is_empty() && has_term( $category, 'product_cat', $product_id ) ) { wc_add_notice( __('Sorry you can only order this sample product on its own.', 'woocommerce' ), 'error' ); return false; } return $passed; }
Of course the first part of the linked code underwhich first part lol
perfect, was assuming, thanks manOf course the first part of the linked code under
"// Remove other items when our specific product is added to cart"