This snippet can be used for many ways. For instance, your store only allows to buy one product at a time such as “Buy Now”.
Open functions.php under your activated theme and put the code below:
// Only one product in cart add_filter( 'woocommerce_add_cart_item_data', 'only_one_product_in_cart' ); function only_one_product_in_cart( $cart_item_data ) { global $woocommerce; $woocommerce->cart->empty_cart(); return $cart_item_data; }
Now you can test by adding new product to your existing cart with items, see whether it will added the latest product only and remove all previous products in the cart.
Views (2146)
The following two tabs change content below.

Chris Mok
Senior Developer at GNA eMarketing
Core Contributor on the WordPress.org

Latest posts by Chris Mok (see all)
- WHM – Change account setup date manually - August 25, 2016
- Manually generate the notifications to who over disk quota - August 23, 2016
- Help Desk Management: What is Level 1, Level 2, and Level 3 Help Desk support? - July 27, 2016
- Find and delete files greater than a given size from the Linux command line - April 18, 2016
- How to change WordPress default email’s From name and address - April 15, 2016