Last active
April 21, 2022 01:42
-
-
Save aslamdoctor/30131547a0e4d7a2ca5ede616d386e27 to your computer and use it in GitHub Desktop.
Woocommerce : Update Cart Count & Mini Cart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Add this to Header --> | |
<div class="header-mini-cart"><?php woocommerce_mini_cart();?></div> | |
<?php | |
// Update Cart Count & Mini Cart | |
add_filter( 'woocommerce_add_to_cart_fragments', 'iconic_cart_count_fragments', 10, 1 ); | |
function iconic_cart_count_fragments( $fragments ) { | |
if(!empty(WC()->cart->get_cart_contents_count())){ | |
$fragments['span.menu-cart-count'] = '<span class="cart-count menu-cart-count">(' . WC()->cart->get_cart_contents_count() . ')</span>'; | |
ob_start(); | |
echo '<div class="header-mini-cart">'; | |
woocommerce_mini_cart(); | |
echo '</div>'; | |
$fragments['div.header-mini-cart'] = ob_get_clean(); | |
} | |
return $fragments; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment