Skip to content

Instantly share code, notes, and snippets.

@kloon
Last active January 26, 2024 18:14
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save kloon/4541017 to your computer and use it in GitHub Desktop.
Save kloon/4541017 to your computer and use it in GitHub Desktop.
WooCommerce Clear Cart via URL
// check for clear-cart get param to clear the cart, append ?clear-cart to any site url to trigger this
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
if ( isset( $_GET['clear-cart'] ) ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
}
}
@its-leofisher
Copy link

Credits: How To Add an Empty Cart Button to WooCommerce

Works, but missing exit after wp_safe_redirect().

Adding exit did the trick

@ekazoom
Copy link

ekazoom commented Jan 26, 2024

These all stopped working. I can't clear my cart with any of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment