I need to retrieve all the images of a variation, I can get the first image with $variation = wc_get_product( $variation_id ); $updated_image_id = $variation->get_image_id('edit');
but how can I get all the additional variation images if I know the variation id?
You can try this - Not tested though.
$args = array(
'post_parent' => $variation_id,
'post_type' => 'attachment',
'post_mime_type' => 'image'
);
$images = get_children( $args );
if ( empty($images) ) {
// no attachments here
} else {
foreach ( $images as $attachment_id => $attachment ) {
//Do whatever here
echo wp_get_attachment_image( $attachment_id, 'full' );
}
}
You can get a list of the product's variations:
// In the product loop:
$variations = $product->get_available_variations();
// Outside the product loop:
$product = new WC_Product_Variable( $product_id );
$variations = $product->get_available_variations();
Loop over it to get the image from each variation like so:
foreach ( $variations as $variation ) {
echo $variation['image_src'];
}