Woocommerce

Clear Cart with a Link in Woocommerce

By July 20, 2020August 3rd, 2020No Comments

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/

Contact us to learn about adopting the web for your business

Jarod Thornton

Author Jarod Thornton

More posts by Jarod Thornton