ajax update cart woocommerce code example
Example: woocommerce update mini cart ajax
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;
} );
add_filter( 'woocommerce_add_to_cart_fragments', function($fragments) {
ob_start();
?>
<div class="header-quickcart">
<?php woocommerce_mini_cart(); ?>
</div>
<?php $fragments['div.header-quickcart'] = ob_get_clean();
return $fragments;
} );