Get the total number of items for a specific product inside the cart and display it within the loop

I’m trying to figure how I can reflect or display the total number of items the user has added on a single item within the loop. This is to indicate the total number of a particular item the user has added inside the cart

I managed to display the text with the help of the documentation but it seems to fetch all the quantities of all the items inside the cart.

<div class="container">

            <?php
            $args = array(
                    'post_type' => 'product',
            );

            $crate_products = new WP_Query ( $args );
            if ( $crate_products->have_posts() ) : while ( $crate_products->have_posts() ) :
              $crate_products->the_post();

            ?>

            <div id="post-<?php the_ID() ?>" class="three columns product-post">
              <?php
                  global $woocommerce;
                  $items = $woocommerce->cart->get_cart();

                      foreach($items as $item => $values) {
                          $_product = $values['product_id']->post;
                          echo "<b>" . '</b>  <br> Quantity: '.$values['quantity'].'<br>';
                      }
              ?>


                <?php  wc_get_template_part('content', 'product'); ?>



            </div>

            <?php wp_reset_postdata(); ?>

            <?php endwhile; else: ?>

            <?php endif; ?>

            <?php wp_reset_query(); ?>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.