Home » WooCommerce: Only Allow 1 Product in the Cart

WooCommerce: Only Allow 1 Product in the Cart

by Tutor Aspire

Here’s how to limit your WooCommerce Cart to just one product at a time.

This simple PHP snippet can be used for many applications. For example, your store may only allow to buy one subscription at a time. On this same website, on the other hand, customers can only purchase one product at a time so it’s easier for me to manage invoicing and payments, given that I switch PayPal and Stripe accounts based on what’s inside the cart.

Here’s the quick fix – enjoy!

WooCommerce: only allow 1 product in the cart

PHP Snippet: Limit the Cart to Max One Product – WooCommerce

/**
 * @snippet       WooCommerce Max 1 Product @ Cart
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WC 5.1
 * @donate $9     https://www.tutoraspire.com
 */
 
add_filter( 'woocommerce_add_to_cart_validation', 'tutoraspire_only_one_in_cart', 9999, 2 );
  
function tutoraspire_only_one_in_cart( $passed, $added_product_id ) {
   wc_empty_cart();
   return $passed;
}

You may also like