Ask your WordPress questions! Pay money and get answers fast! (more info)

WooCommerce product quantites WordPress

  • REFUNDED

When a WooCommerce product is displayed in Grid view or on a Single page, I would like to display how many of this particular product has already been added to the customers cart. If there are no products of this type in the cart, no quantity is shown. Quantity totals should update dynamically via Ajax as items are added via the 'Add to Cart' button.

When the customer completes an order, all product quantities should reset to zero/disappear. Similarly, if the option 'Clear cart when logging out' under 'Settings > General > Cart, Checkout and Accounts' is set to 'True', all product quantities should be reset to zero when the customer logs out.

Please can someone help me write a function that achieves the above requirements.

Many thanks.

Answers (2)

2013-04-23

Daniel Yoen answers:

to show cart contents, put this line where you will display the cart :

<?php global $woocommerce; ?>

<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>


Update cart with ajax(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-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
<?php

$fragments['a.cart-contents'] = ob_get_clean();

return $fragments;

}


ref: http://docs.woothemes.com/document/show-cart-contents-total/

hope this help :-)


designbuildtest comments:

Hi Daniel, I don't think you have understood the question unfortunately. Your solution simply outputs a link to the cart and displays the total number of items in the cart and their total value.

2013-04-24

Romel Apuya answers:

Hi,

I get what you mean. Im not a woo-commerce expert but Im expert in programming
If you can give me access to the code i can probably help

cheers,,

romel