Skip to content

Instantly share code, notes, and snippets.

@renzoster
Created July 6, 2019 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renzoster/1429b81f6f4a44181a978cee5338ae84 to your computer and use it in GitHub Desktop.
Save renzoster/1429b81f6f4a44181a978cee5338ae84 to your computer and use it in GitHub Desktop.
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