Skip to content

Instantly share code, notes, and snippets.

@yanknudtskov
Created April 18, 2018 17:38
Show Gist options
  • Save yanknudtskov/7fdf249b8f86a9b2a3493201114d97db to your computer and use it in GitHub Desktop.
Save yanknudtskov/7fdf249b8f86a9b2a3493201114d97db to your computer and use it in GitHub Desktop.
Clear the #woocommerce #cart with a query string parameter
<?php
/*
* If you add ?clear-cart to the URL the cart will be emptied
*/
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
if ( isset( $_GET['clear-cart'] ) ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment