Woocommerce Individual Products

tanierlyons

Well-known member
Staff member
Administrative
Moderator
May 24, 2018
75,217
111,760
120

Rubixvi

Well-known member
Trusted Uploader

frizzel

Well-known member
Trusted Uploader
Jun 13, 2019
485
253
63
Wherever my imagination takes me
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;
}
 

Rubixvi

Well-known member
Trusted Uploader
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
 

Forum statistics

Threads
69,485
Messages
909,976
Members
239,849
Latest member
adskjdhsa

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu