Personalized checkout and custom promotions with Shopify Scripts
Hello,
I would like to show conditional metafield for each cart item added inside cart. I created a for loop with if condition. code is working but for loop prints all metafields for each cart item rather than relevant metafield value. See the attached screenshot. Thanks for the help
{% for item in cart.items %}
{% if item.variant.metafields.variant.stocked_sku %}
<p>Usually Ships in {{ item.variant.metafields.variant.stocked_lead_time }} Days</p>
{% else %}
<p>Made to Order: Usually Ships in {{ item.variant.metafields.variant.mto_lead_time }} Days</p>
{% endif %}
{% endfor %}
Why is your code within a for loop?
The cart page would already be looping over the items so it looks like you are adding a second loop that isn't needed. Do you get better results if you remove the for loop and just leave the contents of it?
Your code also assumes that either of those metafields exist and it might not always be the case. Adding something to catch that (and just skip showing anything) would be a good idea.
I also want to know how to solve this problem!
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023