How To Ajaxify Header Cart Items Count In Woocommerce

Share Now

Share on facebook
Share on pinterest
Share on twitter
Share on linkedin
Share on email

1. Add this code in function.php file:

add_filter( 'woocommerce_add_to_cart_fragments', 'wc_refresh_mini_cart_count');
function wc_refresh_mini_cart_count($fragments){
    <span class="number-of-product-in-store">
        <?php echo WC()->cart->get_cart_contents_count(); ?>
        $fragments['.number-of-product-in-store'] = ob_get_clean();
    return $fragments;

2. Now add these code on the section where you want to show your Cart Items count.

<span class="number-of-product-in-store"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert