Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Hi,
I am using the advanced flow action to get order data from the last day and then send an internal email.
I won't go over the full use case but I'd like to get product titles only when that product has a certain metafield value
This is what I have (where the CAPS things are replaced with the real values)
Hi,
Each product could have multiple metafields. I believe that you need to do a for loop on the metafields as well. Something like:
....
{% for metafield_item in lineItems_item.product.metafields %}
{% if if metafields_item.key == "key" and metafields_item.value="value" %}
{{lineItems_item.product.title}}
....
Lily
To learn more visit the Shopify Help Center or the Community Blog.
Thanks!
I tried something like that and it still returns nothing
{% for getOrderData_item in getOrderData %}
{% for lineItems_item in getOrderData_item.lineItems %}
{% for metafields_item in lineItems_item.product.metafields %}
{% if metafields_item.key == "KEY" and metafields_item.value == "VALUE" %}
{{lineItems_item.product.title}}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
Wondering if there is a weird scope thing going on that I don't understand because the metafield value is definitely present on at least one item.
I might start be removing the IF statement and echoing out the metafield values like {{ metafields_item.value }}. If it has metafields and they don't print out then, your scoping idea may be correct.
Thanks @paul_n
I've removed the if statements and used this instead
{% for getOrderData_item in getOrderData %}
{% for lineItems_item in getOrderData_item.lineItems %}
{% for metafields_item in lineItems_item.product.metafields %}
{{lineItems_item.product.title}} {{metafields_item.value}}
{% endfor %}
{% endfor %}
{% endfor %}
That gives me a list of the products with their various metafield values next to it
Product 1 Metafield_value
Product 1 Metafield_value
Product 1 Metafield_value
Product 2 Metafield_value
etc.
This seems to imply that I can access those metafields and product.title in those loops so the question remains why the if statement stops it working
Really odd. It's not a particularly complex bit of liquid and I think the syntax is good and the mf namespace.keys.values all labelled correctly.
So really not sure why I can't limit the data like this.
p.s. I have also tried putting a condition in front of this to look for the metafield namespace.key.value but that also doesn't work.
Are you sure you want to check the value in the "if" and not the "namespace" and "key"? Are you sure the key name is what you think it is? FYI, Flow does not use dot notation with metafields yet so things like "metafields.custom.my_key" will not work.
Yep. I'm sure i want to check the value.
That metafield is a true/false one I want to only output the product titles where it was set as true.
The actual use case is that we have some items that as a charity shop we have some items that are gift aidable. I would like to be able to output product details in from the advanced workflow where the gift aid metafield is set to true.
It's odd that you say flow doesn't work with dot notation because I'm using it in a few other places fine. unless I'm misunderstanding what you're saying of course.
By dot notation, I mean you cannot access metafields specifically like {{ order.metafields.my_name.my_key }} as you can in storefront liquid. Otherwise it works.
I think your condition has the wrong value or key name. I think to check for a boolean metafield it may be case sensitive so has to be the string "True"
Hi @paul_n
Thanks for the help. I'm afraid it still doesn't work.
Here's the metafield
And here's the code in the flow action
It still returns nothing.
At this point I'm thinking that the advanced workflows maybe just won't be able to do what we thought they could. The only thing I can think of would be whether we could put the metafield value filter on getOrderData action itself.
Is that possible do you know?