Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi,
I'm trying to join the values within each products metafield into a new variable and then add this to the order metafield. I think the values from each products metafields are in arrays that need to be combined in order to then pass the combined values into the correpsponding metafield on the order.
Example:
I combine these into a variable which I think try to put into the order metafield using this code:
{% capture metaDepartment %} {% for lineItems_item in order.lineItems %} {% for metafields_item in lineItems_item.product.metafields %} {% if metafields_item.namespace == "product" and metafields_item.key == "department" %} {{ metafields_item.value | remove: "[" | remove: "]" | remove: '"' | split: ", " }} {% endif %} {% endfor %} {% endfor %} {% endcapture%} {{ metaDepartment }}
I get this error though.
What I'm wondering is whether I can join it all together in a way that will be accepted into the new order metafield, and for this to work no matter how many products I have in the order.
My thinking is that I need to retain it in ["value", "value2", "value3"] format but lose the square brackets except the very first and very last and then join arrays using, to get it into the above format.
Having trouble getting there though. Anyone know? Am I barking up the wrong tree here?
Thanks
Hello! Not sure your question is still relevant. By the way, did you try to use a filter on your metafield value? Like instead of removing all of this things, just use:
{{ metafields_item.value | metafield_text}}
Let me know please works it in your case or not
Hi @moek,
That's a good suggestion. unfortunately it is one of those filters that isn't available in Flow. I did eventually get to a solution on this though.
Can you share with me the solution? I am having the same issue
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025