Created
June 14, 2023 07:26
-
-
Save xardit/760215cbc302c94668a02b5ec68623e8 to your computer and use it in GitHub Desktop.
WP Woocommerce - Clear cart before adding new one
This file contains hidden or 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 | |
// clear cart before adding new one | |
add_filter( 'woocommerce_add_to_cart_validation', 'remove_cart_item_before_add_to_cart', 20, 3 ); | |
function remove_cart_item_before_add_to_cart( $passed, $product_id, $quantity ) { | |
if( ! WC()->cart->is_empty() ) | |
WC()->cart->empty_cart(); | |
return $passed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment