I need to refill the mini basket when the product is added via ajax to the basket. I am able to update the cart quantity using the woocommerce_add_to_cart_fragments filter as follows:
add_filter( 'woocommerce_add_to_cart_fragments', function($fragments) { ob_start(); ?> <div class="cart-contents"> <?php echo WC()->cart->get_cart_contents_count(); ?> </div> <?php $fragments['div.cart-contents'] = ob_get_clean(); return $fragments; } );
And my HTML markup
<div class="cart-contents"> <?php echo WC()->cart->get_cart_contents_count(); ?> </div>
Duster that is hidden by a div that shows on .cart-content hover
<div class="header-quickcart"><?php woocommerce_mini_cart(); ?></div>
I want to update this div content in the same way or similar to woocommerce_add_to_cart_fragments. Or do I need to change the HTML markup and save everything in 1 div? What is the general way or best practice for this?
source share