If your still interested this is the way I did what I think you want.
In your functions.php
/**
* Clear Cart for WooCommerce - goes in functions.php
*/
function woocommerce_clear_cart_url() {
global $woocommerce;
if( isset($_REQUEST['empty']) ) {
$woocommerce->cart->empty_cart();
}
}
add_action( 'init', 'woocommerce_clear_cart_url' );
Next in your functions.php
/*create ajax action to clear cart*/
function my_custom_function(){
global $woocommerce;
$woocommerce->cart->empty_cart();
}
add_action('wp_ajax_empty', 'my_custom_function');
add_action('wp_ajax_nopriv_empty', 'my_custom_function');
Also in functions.php
/*add button to cart pull out*/
add_action( 'woocommerce_widget_shopping_cart_buttons', 'add_clear_cart_button', 20 );
function add_clear_cart_button() {
?>
<a>?empty=empty-cart"><button class="btn fa-input2 btn fa-input" name="empty" id="btnclear" style="width: 100% !important; margin-bottom: 6px !important; margin-left: 0px !important;"><?php _e('Empty Cart','woocommerce'); ?></button></a>
//you can use your own styles
<style>.btn.fa-input2{
background-color: #C60C00;
background: -moz-linear-gradient(top,#C60C00 0%,#000 100%);
background: -webkit-linear-gradient(top,#C60C00 0%,#000 100%);
background: -o-linear-gradient(top,#C60C00 0%,#000 100%);
background: -ms-linear-gradient(top,#C60C00 0%,#000 100%);
background: linear-gradient(to bottom,#C60C00 0%,#000 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#C60C00',endColorstr='#000',GradientType=0));
}
.btn.fa-input2:hover{
opacity: .8;
}
</style>
<?php
}
Now you need to create a js file and enqueue it
jQuery(function($){
$('#btnclear').click(function(){
$.ajax({
url: '/wp-admin/admin-ajax.php',
type: "POST",
cache: false,
data: {action: 'empty'} //action defines which function to use in add_action
});
});
});
You can style the button any way you like. Hope this works for ya’.
-
This reply was modified 5 years, 11 months ago by carver1g. Reason: missing backtic