I want to show product variation images (particular image for each variation) on the shop page. I was successfully able to get the name of the variations using the code below (put into “content-product.php”):
<?php
$colourvalues = get_the_terms( $product->id, 'pa_colour');
foreach ( $colourvalues as $colourvalue ) {
echo $colourvalue->name;
}
?>
Unfortunately there is nothing in the $colouvalues
array that is the variations image url or anything related to the image.
How can I get product variation images?
You can get a list of the product’s variations:
Loop over it to get the image from each variation like so:
For Woocommerce 3. loop over like this once you create the variations array.
in functions file