• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Woocommerce Individual Products

Anyone know a way to restrict products from being sold with any other products?
you mean if someone buy product 1 cant buy product 4 or product 10 ?
 
Trying to change the way it works where the restricted product doesn't get added rather than removing all other products.
Replace 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;
}
 
Replace 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;
}
which first part lol
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock