What's your biggest current challenge? Have your say in Community Polls along the right column.

Why isn't my liquid code working in Flow?

Why isn't my liquid code working in Flow?

vanillamt
Shopify Partner
6 0 3

Can anyone tell me why this code refuses to be accepted by Shopify Flow please?

 

{% for line_item in order.line_items %}
{% if line_item.product.metafields.availability contains 'NOT Available' or line_item.product.metafields.logistics contains 'Item is not available to order' %}
{{line_item.sku}}
{% endif %}
{% endfor %}

 

I get the error:

 

  • "line_items" is invalid. Replace this variable.
Replies 3 (3)

Moira
Shopify Staff (Retired)
2118 231 337

Hey @vanillamt,

 

It looks like the error message is indicating that the variable "line_items" is not valid and needs to be replaced.

 

Some possible causes of this error could include:

  • "line_items" is not a valid variable within the context of your code
  • There is a typo in the variable name, and it should be "line_item" instead
  • You are using an outdated version of Shopify's Liquid template language and the variable name has been changed or deprecated.

 

I would recommend double-checking the variable name and making sure it is spelled correctly and that it is a valid variable in the context of your code. Also, check the version of the liquid template, if it is outdated, update it. Also, you can check Shopify's documentation for the version you're using to ensure that the variable is still supported.

Moira | Social Care @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog

pit1
Shopify Partner
49 0 13

Same problem with this code 

  • {% for item in order.lineItems_item %} {% if item.title contains 'XX' %} {% assign aa= item.variant.options[0] %} {% assign bb= item.variant.options[1] %} {% assign cc= item.variant.options[2] %} XX{{ aa }}_{{ bb}}_{{ cc}} {% endif %} {% endfor %}
paul_n
Shopify Staff
1445 157 334

So first, Flow liquid is not same as storefront liquid (see https://help.shopify.com/en/manual/shopify-flow/reference/variables). Use "Add a variable" to gauge the syntax. So "order.line_items" is "order.lineItems" in Flow. 

 

Second, you cannot access array items that way, like "item.variants.options[1]". You can loop over arrays to get their items.

 

Finally, I'm not sure where you got "order.lineItems_item" but that's not a field name. To access lineItems, typically you would use this loop:

{% for li in order.lineItems %}
{% if li.title == "something" %}
print out something
{% endif %}
{% endfor %}



 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.