php - Update details in cart widget without loading page by using ajax in Woocommerce -
i developing woocommerce widget show cart subtotal, cart total, cart items, , shipping total working fine want update shipping total cart total whenever toggle between shipping methods use of ajax. updates after page reload. there hook available purpose ?
you can add_to_cart_fragments
filter.
my implementation updates number of items shown ajax can used update totals, etc well. normal code in template displays cart details:
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>"> (<?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count); ?>)</a>
this filter added in functions.php
:
// update items in cart via ajax add_filter('add_to_cart_fragments', 'woo_add_to_cart_ajax'); function woo_add_to_cart_ajax( $fragments ) { global $woocommerce; ob_start(); ?> <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>">(<?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count); ?>)</a> <?php $fragments['a.cart-contents'] = ob_get_clean(); return $fragments; }
there resources / documentation on out there - remember using reference when wrote code bit tough google for.
Comments
Post a Comment