Skip to content

Instantly share code, notes, and snippets.

@kamalinfo
Last active January 30, 2018 03:58
Show Gist options
  • Save kamalinfo/14b529235a4eefb5afec1936af9f1e28 to your computer and use it in GitHub Desktop.
Save kamalinfo/14b529235a4eefb5afec1936af9f1e28 to your computer and use it in GitHub Desktop.
<?php
//functions php
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
<a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>" title="<?php esc_html_e('View your shopping cart', 'text_domain'); ?>">
<span class="htc__qua"><?php echo esc_html( $woocommerce->cart->cart_contents_count ); ?></span>
</a>
<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
//where need
global $woocommerce;
<a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'text_domain'); ?>">
<span class="htc__qua"><?php echo esc_html( $woocommerce->cart->cart_contents_count ); ?></span></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment