Woocommerce: Cart only 1 Item at a Time

  • Post author:
  • Post last modified:September 16, 2023

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;
}