Choosing a selection results in a full page refresh.
document.addEventListener('DOMContentLoaded', function () {
// Grab all variant images that are linked to variants
const variantImages = document.querySelectorAll('[data-variant-image]');
variantImages.forEach(image => {
// Add an event listener for a click event on each variant image
image.addEventListener('click', function () {
const variantId = this.getAttribute('data-variant-id');
// If the variantId attribute is found, set it as the selected variant
if (variantId) {
const selectElement = document.querySelector('select[name="id"]');
if (selectElement) {
selectElement.value = variantId;
// Dispatch a change event to update the selection
const event = new Event('change');
selectElement.dispatchEvent(event);
}
}
});
});
});