Created
March 16, 2020 13:51
-
-
Save naflan121/13aa48924a4ebef51312f19a45f9ac8f to your computer and use it in GitHub Desktop.
Woocommerce Only One Product inside Cart- Emply cart before adding new products
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
/** | |
* @snippet WooCommerce Max 1 Product @ Cart- Empty cart before adding new | |
* @how-to code goes inside functions.php | |
* @author Random | |
* @compatible WC 3+ | |
*/ | |
add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart' ); | |
function woo_custom_add_to_cart( $cart_item_data ) { | |
global $woocommerce; | |
$woocommerce->cart->empty_cart(); | |
// Do nothing with the data and return | |
return $cart_item_data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment