Only Allow 1 Product in the Cart WooCommerce

Only Allow 1 Product in the Cart WooCommerce
103 Views

We can set add to cart limit on WooCommerce cart using woocommerce_add_to_cart_validation filter. Add below code on functions.php file to limit your WooCommerce Cart to just 1 product.

screenshot webbydemo.in 2022.12.27 17 37 26
<?php
add_filter( 'woocommerce_add_to_cart_validation', 'cxc_woocommerce_only_one_product_in_cart', 99, 2 );

function cxc_woocommerce_only_one_product_in_cart( $passed, $added_product_id ) {
	wc_empty_cart(); /* For make cart empty. */
	return $passed;
}
?>
Was this article helpful?
YesNo

Leave a comment

Your email address will not be published.