WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] How to get quantity of product? (8 posts)

  1. ardziej
    Member
    Posted 1 year ago #

    Hi, how I can get quantity of product ?

    Best ;)

    http://wordpress.org/extend/plugins/woocommerce/

  2. daileycon
    Member
    Posted 1 year ago #

    We need more details than that.

  3. Coen Jacobs
    Member
    Plugin Author

    Posted 1 year 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
    Member
    Posted 1 year ago #

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

    e.g
    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
    Member
    Plugin Author

    Posted 1 year 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
    Member
    Posted 1 year 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. PaweĊ‚ Nowak
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

    @pawel

    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>

    Credit:
    https://gist.github.com/mikejolley/2044101

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.