I want to be able to change product description based on variant name. I am following the tutorial here ==> https://ecommerce.shopify.com/c/ecommerce-design/t/demo-change-description-in-product-with-different-variants-296509
I modified the code a bit in order to use variant.option1 instead of variant.id
Seems like I have no luck as the description is not changing. Option 1 has “Unisex Tee” and “Women’s Tee”
Below is the code:
<p class="description" id="Unisex Tee">Unisex Tee</p>
<p class="description" id="Women's Tee" style="display: none;">Women's Tee</p>
// selectCallback is the callback name in Timber
var selectCallback = function(variant, selector) {
// Simply toggle on/off the panel according to the variant selected
$('.description').css('display', 'none');
$('#' + variant.option1).css('display', 'block');
// rest of the Timber code
}
Any help would be greatly appreciated as I am not really good with JS. Thanks.
3
Answers
Modify the code back to use the variant IDs. The
option1
property of thevariant
object is not guaranteed to provide you validid
names, as is what is happening in your case. For instance, spaces are not allowed inid
attributes and neither is the single quote. Read this and this for more details. This is why the author of that post was using variant ID. It is a unique identifier and it is also a validid
for HTML elements.