Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Hello!
I'm experimenting with Shopify Flow to generate point accumulation for customers after each purchase. I've made a customer metafield, customer.metafield.loyalty.points set to JSON, that would store accumulated points value. Now I'm trying to make a Flow that would fetch the existing value of the metafield and add 5% of the new order value to it.
See the image attached - what code should I put in the value field in order to achieve this? Or am I getting the whole idea wrong and this should be done elsewhere rather than Flow?
Solved! Go to the solution
This is an accepted solution.
Hi A_oxolins,
Flow isn't able to access metafields through the dot-delimited way that the Online Store editor can.
Liquid like this to replace the first line of your `Value` field may help:
{% assign accumulation = 0 %}
{% for metafields_item in order.customer.metafields %}
{% if metafields_item.namespace == "loyalty" and metafields_item.key == "points" %}
{% assign accumulation = metafields_item.value %}
{% endif %}
{% endfor %}
Hope that helps!
This is an accepted solution.
Hi A_oxolins,
Flow isn't able to access metafields through the dot-delimited way that the Online Store editor can.
Liquid like this to replace the first line of your `Value` field may help:
{% assign accumulation = 0 %}
{% for metafields_item in order.customer.metafields %}
{% if metafields_item.namespace == "loyalty" and metafields_item.key == "points" %}
{% assign accumulation = metafields_item.value %}
{% endif %}
{% endfor %}
Hope that helps!
Thank you, Dave! That worked like a charm!
@DaveMcV could you please help me? I have a similar issue to this, the code is outputting blank lines to Log output
The metafield looks like, eg, By (author) Marcus Rashford , Illustrated by Marta Kissi
{% assign author = '' %}
{% for metafields_item in product.metafields %}
{% if metafields_item.namespace == "product" and metafields_item.key == "contributor" %}
{% assign author = metafields_item.value | split: "," | first | remove: "By (author) "%}
{% endif %}
{% endfor %}
{{ author }}
@cybko That appears correct to me. Have you tried just assigning the metafield value without any filters to see what happens? It's possible the value isn't found or isn't what you expect. If you are getting what you expect, then you could try applying the liquid filters one by one until you find the one causing the issue.
To learn more visit the Shopify Help Center or the Community Blog.
I have, yeah, it just outputs blankly even when the metafield isn't blank (using the log output action). It's definitely a single line text as well.
I actually just tried outputting ALL metafields, and it exists there.
It's hard to know without some more details. Could you post screenshots of the workflow run log, the metafield definition, and the metafield value on the product from that run?
To learn more visit the Shopify Help Center or the Community Blog.
Hi Jeff, I'd made a mistake, I have it all sorted now. Thank you for responding so quickly and thoroughly.
The year-end shopping spree is around the corner! Is your online store ready for the ...
By JasonH Nov 10, 2024We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024