By default woocommerce, you cannot clear entire cart with oneclick, To do this,you can add this is two steps. The first one is to add this little snippet in your functions.php file (this file is located in your theme folder):
// 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();
}
}
And the second step is to create a custom template for the cart. Basically a custom template allow you to override WooCommerce default files and use your own custom files instead. Here is a quick tutorial that will explain you how to create your custom templates: http://docs.woothemes.com/document/template-structure/
Finally, in “templates/cart/cart.php”, 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>
Responses
0 Respones to "How to Create a “Empty Cart” button for WooCommerce"
Post a Comment