Viewing 7 replies - 1 through 7 (of 7 total)
  • We need more details than that.

    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.

    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.

    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.)

    @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.

    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?

    @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

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to get quantity of product?’ is closed to new replies.