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;

	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 (2189)

Leave a Reply

Your email address will not be published. Required fields are marked *

11 − ten =