Scroll to top

How to Update Custom Cart Count with AJAX in WooCommerce?


Notice: Undefined variable: string in /home/u665484253/domains/wpcodekit.com/public_html/wp-content/themes/twentytwenty-child/functions.php on line 61

How to Update Custom Cart Count with AJAX in WooCommerce?

function totalcartqty(){

?>
<div class=”header-cart-count”><?php echo WC()->cart->get_cart_contents_count(); ?></div>
<?php
}

add_action(‘wp_head’,’totalcartqty’);

add_filter( ‘woocommerce_add_to_cart_fragments’, ‘iconic_cart_count_fragments’, 10, 1 );

function iconic_cart_count_fragments( $fragments ) {

$fragments[‘div.header-cart-count’] = ‘<div class=”header-cart-count”>’ . WC()->cart->get_cart_contents_count() . ‘</div>’;

return $fragments;

}

Get more information

 

Read More Posts

Leave a Reply

Your email address will not be published.