Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi,
I'm trying to pass metafield values from products/lineItems to corresponding MFs on the order.
The code for is pretty janky. I've had to deconstruct and then reconstruct the ["value", "value"] format.
It works, unless there is a product in the order where that metafield is left empty in which case the empty field gets a "," and breaks everything.
[{% for lineItems_item in order.lineItems %} {% capture metaDepartment %} {% for metafields_item in lineItems_item.product.metafields %}
// THIS LINE NEEDS ADDITION CONDITION {% if metafields_item.namespace == "product" and metafields_item.key == "department" %} {{ metafields_item.value | remove: "[" | remove: "]" }} {% endif %} {% endfor %} {% endcapture%} {{metaDepartment}} {% unless forloop.last %} ,{%endunless%} {% endfor %}]
I have tried adding and metafield_item.value != empty/blank/nil/null to it but each time I try none of them work and it still tries to pull through the empty value.
Any idea how that if condition should work or whether there is a way to structure it better so that if an empty value is carried through it doesn't break everything.
thanks
Thanks for giving it a shot. It doesn't work as expected. Or rather, it works how my other attempts have.
It still brings in the empty mf value and tries to include that in the new variable which introduces the extra "," whihc breaks everything.
But your code was correct which probably means I've messed it up somewhere else. In itself that's really helpful to know.
@Niyeepo thanks for your help on this. I sorted it. Your solution was good code but it didn't work, so I figured my code was bad.
Changed how the variables are created and structured as MF values and it now works.
In Canada, payment processors, like those that provide payment processing services t...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025