Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Created May 26, 2016 15:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BFTrick/4e94862ec64d56164b960aa16701e090 to your computer and use it in GitHub Desktop.
Save BFTrick/4e94862ec64d56164b960aa16701e090 to your computer and use it in GitHub Desktop.
WooCommerce add an Empty Cart button
<?php
// check for empty-cart get param to clear the cart
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
global $woocommerce;
if ( isset( $_GET['empty-cart'] ) ) {
$woocommerce->cart->empty_cart();
}
}
add_action( 'woocommerce_cart_actions', 'patricks_add_clear_cart_button', 20 );
function patricks_add_clear_cart_button() {
echo "<a class='button' href='?empty-cart=true'>" . __( 'Empty Cart', 'woocommerce' ) . "</a>";
}
@MediaPublishing
Copy link

MediaPublishing commented Mar 15, 2018

hmm. works flawless with user logged in here. how come? Wocommerce 3.3.3

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