Skip to content

Instantly share code, notes, and snippets.

@coulterpeterson
Created August 24, 2023 14:30
Show Gist options
  • Save coulterpeterson/e31b4f3d2f19c4b2dc1386051822f47f to your computer and use it in GitHub Desktop.
Save coulterpeterson/e31b4f3d2f19c4b2dc1386051822f47f to your computer and use it in GitHub Desktop.
WooCommerce Limit Cart to 1 Product
/**
* @snippet WooCommerce Max 1 Product @ Cart
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WCooCommerce 7
* @donate $9 https://businessbloomer.com/bloomer-armada/
* Note: technically speaking, the code below will force the product added to cart to replace whatever
* is in the cart, hence will only allow one product in the cart.
* Ref: https://www.businessbloomer.com/woocommerce-allow-1-product-cart/
*/
add_filter( 'woocommerce_add_to_cart_validation', 'bbloomer_only_one_in_cart', 9999 );
function bbloomer_only_one_in_cart( $passed ) {
wc_empty_cart();
return $passed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment