Jason
Jason

Reputation: 449

WooCommerce – Limiting unique cart items to 1, but accept multiple quantities

Customers should only be able to have 1 unique product in their cart, quantities ignored.

Ideally the older cart item (RED SHIRT) is removed when a new cart item (BLUE SHIRT) is added.

Does anyone know how to realise this? The answers and plugins I could find don't work in my solution, because I still need to accept quantities.

Upvotes: 1

Views: 89

Answers (1)

Krunal Bhimajiyani
Krunal Bhimajiyani

Reputation: 1179

This can be done through the woocommerce_add_cart_item_data hook.

In your functions.php file try this:

    function wc_add_to_cart_items( $cart_item_data ) {
        global $woocommerce;
        $woocommerce->cart->empty_cart();
    
        return $cart_item_data;
    }
    add_filter( 'woocommerce_add_cart_item_data', 'wc_add_to_cart_items' );

It is working for me. Users should only be able to have 1 unique product in their cart, quantity also accepts.

Upvotes: 1

Related Questions