12 October 2019

How to Update Custom Cart Count (or any HTML) after AJAX Add to Cart in WooCommerce

 Update Custom Cart Count (or any HTML) after AJAX Add to Cart 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;
   
}

No comments:

Post a Comment

How to create video slider with cuncks of videos without download all videos?

 Create video slider with cuncks of videos without download all videos function custom_video_slider_shortcode() { $slider_id = 'vide...