Created
May 26, 2016 15:05
-
-
Save BFTrick/4e94862ec64d56164b960aa16701e090 to your computer and use it in GitHub Desktop.
WooCommerce add an Empty Cart button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>"; | |
} |
This code is not working when user logged in.When user logged in apply the empty cart button then cart is not empty.This code only working at the time of user logged out.I am using latest version of woocommerce 3.2.2
Hi ! I have the same situation.
Is this code working on the new WP version?
Best,
Hi!
Having the same issue. Works nicely when logged out but fails when logged in...
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
Great, thanks for sharing this solution
Very useful