Skip to content

Instantly share code, notes, and snippets.

@naflan121
Created March 16, 2020 13:51
Show Gist options
  • Save naflan121/13aa48924a4ebef51312f19a45f9ac8f to your computer and use it in GitHub Desktop.
Save naflan121/13aa48924a4ebef51312f19a45f9ac8f to your computer and use it in GitHub Desktop.
Woocommerce Only One Product inside Cart- Emply cart before adding new products
/**
* @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