The code below re-displays each image without resetting at each foreach loop.
For example it gives:
- product 1 - image1
- product 2 - image1+2
- product 3 - image1+2+3 ...
How can I make sure that the pictures of the past products are not displayed again for the following products?
Expected result:
- product 1 - image 1
- product 2 - image 2
- product 3 - image 3 ...
Thank you in advance, here is my code:
<?php foreach ( $last_order->get_items() as $item ) : ?>
<?php
$product = $item->get_product(); // Get the WC_Product object (from order item)
$thumbnail = $product->get_image(array( 50, 50)); // Get the product thumbnail (from product object)
if( $product->get_image_id() > 0 ){
$item_name = '<div class="item-thumbnail">' . $thumbnail . '</div>' . $item_name;
}
echo $item_name . $item->get_name();?>
<?php endforeach;?>