Hi Shopify Community,
I am using Refresh theme.
How can I display in overlay text the variant name in:
-
the selected variant image,
-
each thumbnail variant image.
I have found an example (see below screenshot) on an online store which displays the variant name (black rectangle with white text - “532 GALILEO”) only on the selected variant image but not on the thumbnail images (missing & desired variant name in red)
I have tried with the ChatGPT to suggest a code snippet to add in the product-media-gallery.liquid file and in the section-main-product.css file, but the proposed solution is not working.
See the ChatGPT proposed snippet for the product-media-gallery.liquid file
<!-- Variant name overlay -->
{% if media.attached_to_variant? %}
<div class="variant-name-overlay">{{ media.variant.title }}</div>
{% endif %}
and for the section-main-product.css file:
/* Custom CSS for product variant name overlay */
.variant-name-overlay {
position: absolute;
bottom: 10px;
left: 10px;
color: white;
background-color: rgba(0, 0, 0, 0.5);
padding: 5px;
border-radius: 5px;
font-size: 1rem;
}
ChatGPT is also suggesting to update some JS function updating the content of the variant-name-overlay div when a variant is selected, but I have no idea which that is.
Ensure JavaScript Interactivity: If your theme uses JavaScript to update the displayed image when different variants are selected, ensure the script also updates the variant name in the overlay. This might involve adding or modifying a JavaScript function that updates the content of the variant-name-overlay div when a variant is selected.> >
Another option is to modify the variant images adding in Photoshop the variant name in the image itself.
But that implies download, modify & upload all variant images + alt tag updating - lot of work and cumbersome.
I would prefer a neat code solution.
Please help! thanks
