WooCommerce: Only One product in the cart at a time
If you want to your customers to add only one product in the cart at a time, simply copy and paste the code given below to your themes function.php file. It will remove previously added product from the cart when buyer will add new product to the cart and will add latest product in the cart.
add_filter( 'woocommerce_add_cart_item_data', 'single_item_add_to_cart' ); function single_item_add_to_cart( $cart_single_item ) { global $woocommerce; $woocommerce->cart->empty_cart(); return $cart_single_item; }
[ratings]