I hope someone here can help me out. Quick rundown on my problem I’m trying to display the variant sku above the price and add a few other sections that change when a variant is selected (instruction download link/different meta fields.) I haven’t had any luck.
{% if template contains 'product' %}
{{ 'option_selection.js' | shopify_asset_url | script_tag }}
<script type="text/javascript">
(function($) {
var onVariantSelected = function(variant, selector) {
// Update price display.
var formattedPrice = Shopify.formatMoney(variant.price, "");
$('#product-price').text(formattedPrice);
// Enable or disable the Add to Cart button.
$('#add-to-cart').attr('disabled', variant.available ? null : 'disabled');
// Update the featured image.
if(variant.featured_image) {
var sizedImageUrl = Shopify.Image.getSizedImageUrl(variant.featured_image.src, 'master');
$('#featured-image').attr('src', sizedImageUrl);
}
};
var optionSelectors = new Shopify.OptionSelectors("product-select", { product: {{ product | json }}, onVariantSelected: onVariantSelected, enableHistoryState: true });
// Create an event listener to set a specific variant when clicking on image thumbnails.
$(document).on('click', '[data-change-variant]', function(e) {
e.preventDefault();
optionSelectors.selectVariant($(this).data('changeVariant'));
});
}(jQuery));
</script>
I’m out of ideas on how the variants are working or how to add any new ones, so any help, hints or documentation on adding additional variant data would be so helpful.
I got your point you want to change SKU based on variant change. It is not important where you put code because variant change activity runs through Variant Callback and you have not any SKU related code in it. So please add script code into js file which you have attached here in your above message. If you need any help then let me know.
Thank You for your help, I tried adding that JS code to what I have above and it didn’t work. Do I need to create a separate theme.js.liquid file like in the tutorial?
I’m facing a similar problem with my product variants. The display product image does not change when we select different variants with sizes and colors on the dropdown list on the products page. Any help would be highly apreciated. Thankyou.
@HaiSycamore@VanApp@Akshay_V@chadm320 can you suggest to me on a same issue facing I am on debut theme product section. when variant selected it has change URL - again I am referencing then variant not showing