WooCommerce – Allow only one product in Cart

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[…]