HiI'm trying to get the top cart in woocommerce to automatically update the quantity and price.
I have this to work to some extent, using this as a template:
http://www.amberweinberg.com/developing-custom-woocommerce-themes/
The problem is that I need to use ajax to change 2 elements of not only one,
here is the html that i use in themes fuctions.php files
<div class="cartWrapper"> <a href="#" title="Checkout"> <div id="cartsummary"><p> <span class="cart-bubble cart-contents"><a class="cart-bubble cart-contents"><?php echo sprintf(_n('%d', '%d', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?></a> <?php if($woocommerce->cart->get_cart_url() != ''){ $cart=$woocommerce->cart->get_cart_url();} else {$cart = home_url().'/cart/';}; ?></span> </div> </a> <div id="carttotal"> <div id="cartprice"> <p> <a class="cart-total"><?php echo $woocommerce->cart->get_cart_total() ?></a> </p> </div> <a class="button" href="#" title="Checkout" type="button">View Basket</a> </div> </div>
and code for automatically updating the basket without updating:
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php) add_filter('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-bubble cart-contents"><?php echo sprintf(_n('%d', '%d', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?></a> <a class="cart-total"><?php echo $woocommerce->cart->get_cart_total() ?></a> <?php $fragments['a.cart-contents a.cart-total'] = ob_get_clean(); return $fragments; }
The problem is that while this works, it produces a long list of basket totals and items in the basket that I need to hide using oveflow css style: hidden in the corresponding element. Presumably this is because I incorrectly encoded the ajax element, can someone point me in the right direction?
thanks
source share