Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi everyone
I'm struggling with this problem, seems like only I have it.
I chose a main Picture for my product, but instead of showing it in the product page , it defaults back to the first variant image upon entrance for some reason.
I realized it has something to do with this line of code:
{%- assign featured_media = product.selected_or_first_available_variant.featured_media -%}
But as I lack coding knowledge, I have no idea what to do with it. Everything I try gives back an error or deletes the whole thumbnail section.
Any ideas for how to solve this? The variant picture doesn't match there at all 😞
Hi,
Need to update the Liquid code to use the main product image as the default
Use javascript if required to handle dynamic image changes as per variant
Javascript code example
document.addEventListener('DOMContentLoaded', function () {
var variantSelect = document.querySelector('select[name="id"]'); // Adjust selector as needed
var imageContainer = document.querySelector('.product-image'); // Adjust selector as needed
variantSelect.addEventListener('change', function (event) {
var selectedVariant = event.target.value;
var selectedImage = document.querySelector('.variant-image[data-variant-id="' + selectedVariant + '"]');
if (selectedImage) {
imageContainer.src=selectedImage.src;
}
});
});
Please share your store URL as well
Evetually I found a solution here that worked for me:
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024