How to add "Empty Cart" button on WooCommerce Cart Page?

How to add "Empty Cart" button on WooCommerce Cart Page?


To that, you need to follow two steps.
Step 1: Go to your theme folder. Add the following codes in the function.php file. 

=============================================

// 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(); 
}
}

=============================================

Step 2: You need to create a custom template for cart page. Go to this link to know How To Create Custom Template For Cart
Finally, in “templates/cart/cart.php”, add at line 134 the HTML code to output the button:

<a class="button" href="<?php echo $woocommerce->cart->get_cart_url(); ?>?empty-cart"><?php _e( 'Empty Cart', 'woocommerce' ); ?></a>
DONE !!!! BOOM!!! 


Previous
Next Post »