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
