Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Woocommerce empty cart before add new product to cart.
<?php
/**
* Empty cart. New product will be added. Works with WooCommerce 3.0+
*/
add_filter( 'woocommerce_add_to_cart_validation', 'custom_only_one_in_cart', 99, 2 );
function custom_only_one_in_cart( $passed, $added_product_id ) {
wc_empty_cart();
return $passed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.