Reset Shop page cart counter
-
I need to clean/remove/empty my cart from items added on the shop and single product page. This is not on the cart page.
This cart counter is added with this code under functions.php:
<?php add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' ); function woocommerce_header_add_to_cart_fragment( $fragments ) { ob_start(); ?> <div class="ylbWC-compras"> <div class="ylbWC-compras-items"> <?php echo sprintf (_n( '<b>%d</b> item', '<b>%d</b> items', WC()->cart->cart_contents_count ), WC()->cart->cart_contents_count ); ?> </div> <div class="ylbWC-compras-saco"> <img src="<?php bloginfo('stylesheet_directory'); ?>/imagens/03YL-IconCart.svg" alt="<?php _e('Shop Bag Icon', 'baannngbv5');?>" title="<?php _e('Click to access to account information', 'baannngbv5');?>"/> </div> <div class="ylbWC-compras-total"> <?php echo WC()->cart->get_cart_total(); ?> </div> </div> <?php $fragments['div.ylbWC-compras'] = ob_get_clean(); return $fragments; } ?>
The result is this:
<a href="https://i.stack.imgur.com/MiJWm.png">Image for the Shop page counter (detail)</a>
So I want to reset that counter. I got this to work but only on the second click or when the page refreshes:
<a href="<?php echo $woocommerce->cart->empty_cart(); ?>"><?php _e( 'Empty Cart', 'woocommerce' ); ?></a>
I guess that AJAX would be handy but don’t know how to. I’ve searched and searched for a solution but can’t figure it out! Can someone give me a hand here?Thank you in advanced.
B.
- The topic ‘Reset Shop page cart counter’ is closed to new replies.