Forked from sarachisholm/ four-smart-reasons-to-embed-shopify-store-attachOnVariantSelectListeners.js
Last active
March 20, 2017 17:47
-
-
Save shopifypartners/f76c3cbd9851c79c9fb7c7e681980b22 to your computer and use it in GitHub Desktop.
attachOnVariantSelectListeners for Shopify Buy Button - https://www.shopify.com/partners/blog/four-smart-reasons-to-embed-a-shopify-store-in-your-client-websites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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