Answer the question
In order to leave comments, you need to log in
Empty cart button in woocimmerce?
You need to make a button to empty the basket. Tried to do so
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
global $woocommerce;
if ( isset( $_GET['empty-cart'] ) ) {
$woocommerce->cart->empty_cart();
}
}
<a class="button" href="<?php echo $woocommerce->cart->get_cart_url(); ?>?empty-cart"><?php _e( 'Empty Cart', 'woocommerce' ); ?>
Answer the question
In order to leave comments, you need to log in
Button:
- required in the form tag. Make sure the form is not nested inside another form
Code for functions.php:
add_action('init', 'woocommerce_clear_cart_url');
function woocommerce_clear_cart_url() {
global $woocommerce;
if( isset($_REQUEST['clear-cart']) ) {
$woocommerce->cart->empty_cart();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question