Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Can anyone help with the liquid for a quite basic flow i am trying to setup.
I need the value of a variant metafield with curtain namespace & key, to be tagged to an order.
For example;
"trigger" Order is created
"Filter" Line items is tagged with "preorder"
"Execution" Add order tag = X (value of variant meta field smartpack.exp-date)
Right now we recommend doing looping such as here:
We do have an update coming that will make accessing metafields more straight-forward and not require looping unless the metafield is a list.
Hi paul,
When is this update coming, and would we be able to access a beta, if we are shopify plus customers?
Or can you give me the direct liquid i should put in to access the value of a line item variants meta field called
Namespace: smartpack
Key: expected-date
There won't be a beta - it will be generally available.
If you use "add a variable" to choose "order / lineItems / variant / metafields / namespace" Flow will insert the loop you need. You then add a condition to check the namespace and key and output the values. Something like:
{%- for li in order.lineItems -%}
{%- for mf in li.variant.metafields -%}
{%- if mf.namespace == "smartpark" and mf.key == "expected-date" -%}
{{- mf.value -}}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
Hi Paul,
I am tring but givin me error, can you check if you can find what i am doing wrong here?
36d2b6a698f815a33a4100f1517d1c04e300bfd720da387eca5589d0488ef0d9:{"__metadata":{"version":0.1},"root":{"steps":[{"step_id":"018ead99-fb68-7186-b27c-04ab0dbcaf0c","step_position":[900,1220],"config_field_values":[],"task_id":"shopify::admin::order_created","task_version":"0.1","task_type":"TRIGGER","description":null,"note":null,"name":null},{"step_id":"018ead99-fb68-797c-bbbb-f38576a7b169","step_position":[1260,1220],"config_field_values":[{"config_field_id":"condition","value":"{\"uuid\":\"0cd098fa-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"0cd098f0-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098fa-f329-11ee-a43f-1dc8a70f3d44\",\"array_path\":{\"uuid\":\"0cd098f1-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f0-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"order.lineItems\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"array_item_key\":{\"uuid\":\"0cd098f2-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f0-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"lineItems_item\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"operation\":{\"uuid\":\"0cd098f3-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f0-f329-11ee-a43f-1dc8a70f3d44\",\"array_path\":{\"uuid\":\"0cd098f4-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f3-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"lineItems_item.variant.metafields\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"array_item_key\":{\"uuid\":\"0cd098f5-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f3-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"metafields_item\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"operation\":{\"uuid\":\"1df6db38-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f3-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"0cd098f7-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db38-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"0cd098f8-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f7-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"metafields_item.namespace\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"metafields_item.namespace\"},\"rhs\":{\"uuid\":\"401daf40-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f7-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"smartpack\",\"comparison_value_type\":\"LiteralValue\"},\"value_type\":\"EnvironmentScalarDefinition:String\",\"operator\":\"==\",\"operation_type\":\"Comparison\"},\"rhs\":{\"uuid\":\"1df6db31-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db38-f329-11ee-a43f-1dc8a70f3d44\",\"array_path\":{\"uuid\":\"1df6db32-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db31-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"lineItems_item.variant.metafields\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"array_item_key\":{\"uuid\":\"1df6db33-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db31-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"metafields_item\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"operation\":{\"uuid\":\"2983b453-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db31-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"1df6db35-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"2983b453-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"1df6db36-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db35-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"metafields_item.key\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"metafields_item.key\"},\"rhs\":{\"uuid\":\"3e9d02b0-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db35-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"po-qty\",\"comparison_value_type\":\"LiteralValue\"},\"value_type\":\"EnvironmentScalarDefinition:String\",\"operator\":\"==\",\"operation_type\":\"Comparison\"},\"rhs\":{\"uuid\":\"2983b450-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"2983b453-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"2983b451-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"2983b450-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"metafields_item.value\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"metafields_item.value\"},\"rhs\":{\"uuid\":\"4e9aabd0-f58c-11ee-b75f-4bcf40c11e1f\",\"parent_uuid\":\"2983b450-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"\",\"comparison_value_type\":\"LiteralValue\"},\"value_type\":\"EnvironmentScalarDefinition:String\",\"operator\":\"not_empty_and_not_nil?\",\"operation_type\":\"Comparison\"},\"operator\":\"AND\",\"operation_type\":\"LogicalExpression\"},\"operator\":\"ANY\",\"operation_type\":\"ArrayExpression\"},\"operator\":\"AND\",\"operation_type\":\"LogicalExpression\"},\"operator\":\"ANY\",\"operation_type\":\"ArrayExpression\"},\"operator\":\"ANY\",\"operation_type\":\"ArrayExpression\"},\"operator\":\"AND\",\"operation_type\":\"LogicalExpression\"}"}],"task_id":"shopify::flow::condition","task_version":"0.1","task_type":"CONDITION","description":"Works because even tho it will still in theory activate on orders after the expected date, these will not be sellable as continue overselling is off","note":null,"name":null},{"step_id":"018ead99-fb68-715e-9c7a-309510af8ebd","step_position":[1900,1480],"config_field_values":[{"config_field_id":"order_id","value":"order.id"},{"config_field_id":"tags","value":"[\"{% for lineitems_item in order.lineItems %} {% for metafields_item in lineitems_item.variant.metafields %} {% if metafields_item.namespace == \\\"smartpark\\\" and metafields_item.key == \\\"expected-date\\\" %} {{ metafields_item.value }} {% endif %} {% endfor %} {% endfor %}\"]"}],"task_id":"shopify::admin::add_order_tags","task_version":"0.1","task_type":"ACTION","description":null,"note":null,"name":null},{"step_id":"6f95c490-f330-11ee-a43f-1dc8a70f3d44","step_position":[1620,1220],"config_field_values":[{"config_field_id":"condition","value":"{\"uuid\":\"87a21437-f330-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"87a21430-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21437-f330-11ee-a43f-1dc8a70f3d44\",\"array_path\":{\"uuid\":\"87a21431-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21430-f330-11ee-a43f-1dc8a70f3d44\",\"value\":\"order.lineItems\",\"comparison_value_type\":\"EnvironmentValue\"},\"array_item_key\":{\"uuid\":\"87a21432-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21430-f330-11ee-a43f-1dc8a70f3d44\",\"value\":\"lineItems_item\",\"comparison_value_type\":\"EnvironmentValue\"},\"operation\":{\"uuid\":\"87a21433-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21430-f330-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"87a21434-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21433-f330-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"87a21435-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21434-f330-11ee-a43f-1dc8a70f3d44\",\"value\":\"lineItems_item.variant.inventoryQuantity\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"lineItems_item.variant.inventoryQuantity\"},\"rhs\":{\"uuid\":\"9263ae10-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21434-f330-11ee-a43f-1dc8a70f3d44\",\"value\":\"0\",\"comparison_value_type\":\"LiteralValue\"},\"value_type\":\"EnvironmentScalarDefinition:Int\",\"operator\":\"<\",\"operation_type\":\"Comparison\"},\"operator\":\"AND\",\"operation_type\":\"LogicalExpression\"},\"operator\":\"ANY\",\"operation_type\":\"ArrayExpression\"},\"operator\":\"AND\",\"operation_type\":\"LogicalExpression\"}"}],"task_id":"shopify::flow::condition","task_version":"0.1","task_type":"CONDITION","description":null,"note":null,"name":null}],"links":[{"from_step_id":"018ead99-fb68-7186-b27c-04ab0dbcaf0c","from_port_id":"output","to_step_id":"018ead99-fb68-797c-bbbb-f38576a7b169","to_port_id":"input"},{"from_step_id":"018ead99-fb68-797c-bbbb-f38576a7b169","from_port_id":"true","to_step_id":"6f95c490-f330-11ee-a43f-1dc8a70f3d44","to_port_id":"input"},{"from_step_id":"6f95c490-f330-11ee-a43f-1dc8a70f3d44","from_port_id":"true","to_step_id":"018ead99-fb68-715e-9c7a-309510af8ebd","to_port_id":"input"}],"patched_fields":[],"workflow_name":"Auto tag preorder, with delivery date (preorder setup)"}}
I can't import that. What error are you getting?
This issue:
Looks like you didn't set up the condition correctly. Can you share an image of your condition panel with the side panel open?
Here is condition:
i put in this as tag:
{% for lineitems_item in order.lineItems %} {% for metafields_item in lineitems_item.variant.metafields %} {% if metafields_item.namespace == "smartpark" and metafields_item.key == "expected-date" %} {{ metafields_item.value }} {% endif %} {% endfor %} {% endfor %}
The issue
For that second condition, you need to delete it. When you re-add it, be sure to choose the "Add criteria for same item" right under the first metafield condition (like you add before) and then make sure to select the "metafields_item / key" and NOT variants / metafields /key
Nice, testing it out now if the liquid for the Tag is correct.
I tried putting this liquid for the "add order tags"
That is an order metafield not a variant metafield. you need order / lineItems / variant / metafields
I see what you mean, but can you be more specific?
Does it not have to be a Liquid code when i try to add an order tag?
What to do after the / metafields? How am i sure it uses the specfic value from a specfic metafield i tell it.
Please if you can be more specfic would be amazing
I already gave you the code above.
Hi paul,
So i tried inputting your code above:
{%- for li in order.lineItems -%} {%- for mf in li.variant.metafields -%} {%- if mf.namespace == "smartpark" and mf.key == "expected-date" -%} {{- mf.value -}} {%- endif -%} {%- endfor -%} {%- endfor -%}
And of course adapted the mf to metafields_item etc
Sadly it does not add any tag, even tho the flow is run succesfully.
Only time i get some output, is when i follow the classic tag liquid path. </>
Is there any way where you can make this flow how it should be, and download the file and send it to me.
So close to get it working.
Most likely one of two things is happening:
- Flow is never getting to the action due to your conditional logic (look at the workflow run to verify)
- You have the wrong namespace or key
Assuming the latter, use the Log output action with the same code. It will print out the value. You can add other things to the code so you see what Flow sees, for example I might use:
{%- for li in order.lineItems -%}
{%- for mf in li.variant.metafields -%}
{{mf.namespace}}::{{ mf.key }}::{{mf.value}}
{%- if mf.namespace == "smartpark" and mf.key == "expected-date" -%} {{- mf.value -}} {%- endif -%} {%- endfor -%} {%- endfor -%}
It is running the flow successfully, and i confirmed that it can actually tag when i do the classic way: order / lineItems / variant / metafields
But it stops working if i add custom code to that liquid code, like the stuff you sent above.
It is like it can not filter at all.
Again, is it possible for you to do an example flow that would work, and i could get the file to see it working?
My giving you a workflow isn't going to help because you have the wrong namespace or key entered there, or it's not available on any of the variants.
FYI, the key in your condition is different than the key in the code. If you put that code I just gave you into a log output action, you will see all the metafields on the variants.
The condition was not the problem, the problem was as simple as you had put smartpark and not smartpack.
Now everything works.
All good mate, thank you so much for the help.
🤣 Glad you got there!
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