Created
November 20, 2022 05:51
-
-
Save elias1435/fbcf88186303c5122ed6110d3aecbf55 to your computer and use it in GitHub Desktop.
Empty Woocommerce Cart before adding new item | only 1 product add to cart woocommerce, Code goes in function.php file of your active child theme (or theme)
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
<?php | |
// before addto cart, only allow 1 item in a cart | |
add_filter( 'woocommerce_add_to_cart_validation', 'woo_custom_add_to_cart_before' ); | |
function woo_custom_add_to_cart_before( $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