Personalized checkout and custom promotions with Shopify Scripts
I am using following javascript to get a variant from variant_id. From the script below, I could get response as variant.product_variant in debug console. Problem is the varaint object does not have .image attribute or .image.src attribute and i want the image of the variant to display in .stick-bar-thumb-thumb container. Any help on how to get variant image via javascript or any modification to below code? Thaks
unction updateThumbnailImage(variantId) {
// Construct the URL to fetch variant information
var variantUrl = '/variants/' + variantId + '.json';
// Fetch the variant data using AJAX
fetch(variantUrl)
.then(function (response) {
return response.json();
})
.then(function (variant) {
if (variant && variant.image) {
// Get the URL of the variant's image
var imageUrl = variant.image.src;
// Select the element with the class .sticky-bar-thumb-thumb
var thumbImageElement = document.querySelector('.sticky-bar-thumb-thumb');
// Update the src attribute of the image element
thumbImageElement.src=imageUrl;
}
})
.catch(function (error) {
console.error('Error fetching variant data:', error);
});
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