Skip to content

Instantly share code, notes, and snippets.

@ThemeMetric
Created August 1, 2017 08:50
Show Gist options
  • Save ThemeMetric/f192bf6c5c77b7620ce3e3c561424872 to your computer and use it in GitHub Desktop.
Save ThemeMetric/f192bf6c5c77b7620ce3e3c561424872 to your computer and use it in GitHub Desktop.
woocommerce ajax cart update
function woocommerce_cart_link() {
global $woocommerce;
?>
<a href="<?php echo esc_url($woocommerce->cart->get_cart_url()); ?>" title="<?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> <?php _e('in your shopping cart', 'woothemes'); ?>" class="cart-button ">
<span class="label"><?php esc_html_e('My Basket:', 'woothemes'); ?></span>
<?php echo esc_html($woocommerce->cart->get_cart_total()); ?>
<span class="items"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count); ?></span>
</a>
<?php
}
function header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
woocommerce_cart_link();
$fragments['a.cart-button'] = ob_get_clean();
return $fragments;
}
add_filter('add_to_cart_fragments', 'header_add_to_cart_fragment');
// call this woocommerce_cart_link(); where you want to show the cart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment