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(); ?>
Update
Here is the concept I want to produce. When the user adds a particular item with a specific amount inside the cart. It will then show an icon with the total number of amount for that particular item. I want it to be displayed inside the loop.
Here is an image. The number on the top right corner indicates it has 3 potatoes inside the cart