Add just one product in Woocommerce cart or clean cart

1

Hello, I'm making a subscription club using WooCommerce and I'd like it possible to buy only one product at a time. I thought about maybe cleaning the cart before adding the new product or even limiting the amount of products.

Does anyone know if it's possible?

Thank you.

    
asked by anonymous 10.11.2015 / 13:29

1 answer

0

To clean the cart before adding a new product, you can use the following filter:

add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart' );

function woo_custom_add_to_cart( $cart_item_data ) {

    global $woocommerce;
    $woocommerce->cart->empty_cart();

    // Do nothing with the data and return
    return $cart_item_data;
}

In that SOen thread (which was where I took the above snippet) you can follow a slightly more in-depth discussion on how to do this, as well as how to limit the number of cart items to just 1 which, in practice, is the same thing.)

    
10.11.2015 / 13:56