Created
March 19, 2021 07:18
-
-
Save sarathlal-old/e7c0d3b1e094d943769dd569bccf385e to your computer and use it in GitHub Desktop.
Only allow 1 item in WooCommerce Cart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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