'm trying to dynamically update the secondary image (e.g., side or back view) when a customer hovers over the product image, and I want the image to match the selected color variant.
For example, if a customer selects the “black” variant, the primary image (front view) shows the black product, and when they hover over the image, I want the secondary image (side/back view) for the black variant to display.
Right now, I’m using this code:
assign second_img_position = variant_media.position
However, this only switches to the next image in the sequence, which doesn’t always match the selected color variant. How can I ensure that the secondary image shown on hover matches the color variant selected by the customer?