Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Created May 26, 2016 15:05
Show Gist options
  • 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>";
}
@nicobsas
Copy link

Hi ! I have the same situation.
Is this code working on the new WP version?
Best,

@andregiaever
Copy link

Hi!

Having the same issue. Works nicely when logged out but fails when logged in...

@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