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]));
User | RANK |
---|---|
38 | |
36 | |
24 | |
22 | |
15 |
Transform this holiday season into a shopping spree. Plus, learn how to effortlessly open ...
By Jasonh Dec 8, 2023Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023