Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save encoderit-arman/d3b7a6fa07b5717aa41d2968fab76244 to your computer and use it in GitHub Desktop.
Save encoderit-arman/d3b7a6fa07b5717aa41d2968fab76244 to your computer and use it in GitHub Desktop.
add_filter('woocommerce_cart_contents_count', 'get_total_cart_count');
function get_total_cart_count($count)
{
return count(WC()->cart->get_cart()); // easy!
}
function ajaxify_cart_count_fragments($fragments)
{
// Turn on output buffering
ob_start();
$items_count = count(WC()->cart->get_cart());
// Content
echo '<span class="account-icon-box-single-shop wc-cart-item-total">' . $items_count . '</span>';
// Update fragment with new content
$fragments['.wc-cart-item-total'] = ob_get_clean();
return $fragments;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment