[resolved] How to get quantity of product? (8 posts)

  1. ardziej
    Posted 2 years ago #

    Hi, how I can get quantity of product ?

    Best ;)


  2. daileycon
    Posted 2 years ago #

    We need more details than that.

  3. Coen Jacobs
    Posted 2 years ago #

    If you are looking for the quantity of a product in cart, everything about the products is stored in the $woocommerce->cart->cart_contents variable, which you can access by looking into the $woocommerce global. The cart/checkout is pretty much the only part of the plugin where we use 'quantity' as a word, so my guess is on this.

  4. Yogesh Singh
    Posted 2 years ago #

    Thats good, but how about if i want to pass quantity information with the 'Add to Cart' click.

    If somebody clicks on the 'Add to Cart' button below any specific product, a certain amount of quantity of that product should be added to the cart.

  5. Coen Jacobs
    Posted 2 years ago #

    Check out the cart class, specific to the add_to_cart method:

    public function add_to_cart( $product_id, $quantity = 1, $variation_id = '', $variation = '', $cart_item_data = array() ) {

    The second parameter allows you to add multiple quantities at once. Most of it will be custom code though.

    (Also, please stop hijacking other peoples threads, make your own instead.)

  6. Yogesh Singh
    Posted 2 years ago #

    @coen I am sorry, hope you understand that when somebody is looking for a solution he want to connect with you WC Ninjas as earliest as possible, the idea is not to disturb somebody but to find a solution.

  7. Paulo
    Posted 2 years ago #

    I have the same question:

    How I can get quantity of product and show in another part of my site?

    For ex. in some small box - on the left - like in sidebar (with .hover() function)

    On the left I have got fixed sidebar with menu etc. and at the bottom I'd like to show "my" orders. Exactly => quantity of products.

    Plugins have got some widget called WooCommerce Cart but they are showing everything. I need only quantity of products.

    Is this possible with "cart class" or something like that?

  8. wjkirby287
    Posted 2 years ago #


    Had similar issue, and I found this code:

    <?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>


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.