Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sarathlal-old/e7c0d3b1e094d943769dd569bccf385e to your computer and use it in GitHub Desktop.
Save sarathlal-old/e7c0d3b1e094d943769dd569bccf385e to your computer and use it in GitHub Desktop.
Only allow 1 item in WooCommerce Cart
// before add to cart, empty the existing cart items
add_filter( 'woocommerce_add_to_cart_validation', 'sa53re_custom_woocommerce_add_to_cart_validation' );
function sa53re_custom_woocommerce_add_to_cart_validation( $cart_item_data ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
// Do nothing with the data and return
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment