Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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

//header or woocommerce.php
<div class="header-cart-count"><?php echo WC()->cart->get_cart_contents_count(); ?></div>
//function file
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;
    
}
Source by iconicwp.com #
 
PREVIOUS NEXT
Tagged: #Update #Custom #Cart #Count #AJAX #Add #Cart #WooCommerce
ADD COMMENT
Topic
Name
3+1 =