All things Shopify and commerce
I'm trying to get a variant metafield to render HTML. It's in a capture. The variant works fine on it's own and renders HTML. Only when it's in this piece of code it fails to render. Any suggestions please?
<span class="delivery-message" itemprop="delivery-message">{{ variant.sku }}</span>
{% capture 'meta_data' %} {% for variant in product.variants %} {{ variant.sku | json }}: {{ variant.metafields.custom.delivery_message | json }} {% unless forloop.last %},{% endunless %} {% endfor %} {% endcapture %} <script> var metaData = { {{ meta_data }} } var selectCallback = function(variant, selector) { if (variant) { if (variant.sku != '') { $('.variant-sku').text('SKU: ' + variant.sku); $('.delivery-message').text((metaData[variant.sku])); } } else { $('.variant-sku').empty(); }
Solved! Go to the solution
This is an accepted solution.
Figured it out.
Changed:
$('.delivery-message').text((metaData[variant.sku]));
To:
$('.delivery-message').html((metaData[variant.sku]));
This is an accepted solution.
Figured it out.
Changed:
$('.delivery-message').text((metaData[variant.sku]));
To:
$('.delivery-message').html((metaData[variant.sku]));
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024