I needed a quick and easy way to clear the cart on the fly if needed. This snippet doesn’t disappoint 🙂 Simply append ?clear-cart to the URL to clear the cart – put it in an anchor link if you need it 🙂
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
if ( isset( $_GET['clear-cart'] ) ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
}
}
Thanks Sarathlal N https://sarathlal.com/clear-all-cart-items-using-url-woocommerce/