Skip to content

Instantly share code, notes, and snippets.

@junixdev
Last active June 28, 2016 15:19
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 junixdev/27fefc6d5f1da05b5365fc26ff3b822b to your computer and use it in GitHub Desktop.
Save junixdev/27fefc6d5f1da05b5365fc26ff3b822b to your computer and use it in GitHub Desktop.
force WooCommerce to only have one product in the cart session by emptying the cart session when a product is added
<?php
add_filter( 'woocommerce_add_to_cart_product_id', 'junix_empty_cart_when_product_added' );
function junix_empty_cart_when_product_added( $product_id ) {
if ( $product_id )
WC()->cart->empty_cart();
return $product_id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment