Woocommerce: Cart only 1 Item at a Time

Sourabh Mourya

Sourabh Mourya

Sr. Software Developer
Share on facebook
Share on twitter
Share on pinterest
Share on linkedin

If you are looking for your Woocommerce store to sell only 1 product at a time or you need to purchase 1 product at a time.

Just use the below code snippet to allow only 1 item in the cart at a time. At it to your themes functions.php file or add it inside your custom plugins file.

add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart_one_item' );

function woo_custom_add_to_cart_one_item( $cart_item_data ) {

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

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

Related Stories