Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sarachisholm/51b1c9e57549767f71b4046fcf49c3de to your computer and use it in GitHub Desktop.
Save sarachisholm/51b1c9e57549767f71b4046fcf49c3de to your computer and use it in GitHub Desktop.
function attachOnVariantSelectListeners(product) {
$('.variant-selectors').on('change', 'select', function(event) {
var $element = $(event.target);
var name = $element.attr('name');
var value = $element.val();
product.options.filter(function(option) {
return option.name === name;
})[0].selected = value;
var selectedVariant = product.selectedVariant;
var selectedVariantImage = product.selectedVariantImage;
updateVariantImage(selectedVariantImage);
updateVariantTitle(selectedVariant);
updateVariantPrice(selectedVariant);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment