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
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024