Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Hello,
I have customer information, gender, and birthday, in the customer note section and I'd like to add the info into the customer metafield section automatically.
I tried to do this with Shopify flow but it doesn't work at all.
How do I have to edit the flow?
Plz help!
Solved! Go to the solution
This is an accepted solution.
My fault Dasonjong,
In order to access the first and last element, you need to do this:
birthday | last
I've been trying the code and it works fine with the above-mentioned, except that for some reason, shopify adds some extra newlines characters. You will need a way to remove them in order to make this approach to work. for reference:
gender:
{% assign lines = customer.note | newline_to_br | split: '<br />' %}
{% assign gender = lines | first | split: ':' %}
{{ gender | last }}
birthday:
{% assign lines = customer.note | newline_to_br | split: '<br />' %}
{% assign birthday = lines | last | split: ':' %}
{{ birthday | last }}
Hope this helps.
This is an accepted solution.
The tags themselves add newline characters. You can remove them by using hyphens in that tags. For example, this will remove whitespace before and after the opening {% and closing %}
{%- assign lines = customer.note | newline_to_br | split: '<br />' -%}
Hi Dasoljong,
I noticed that your notes have multiple lines with different fields. Since notes is a text box, your automation will fail. The reason is that when you are trying to assign the result of getting the notes and removing 'birthday', the resulting output will be:
"gender:female
1992-07-08"
and this will not fit in a date shopify field. Can you try with just the birthday in the notes and see if it works that way?
Hello,
Just birthday, it worked.
However, I need gender and birthday.
Isn't it possible?
You can try something like this on the value section:
{% assign lines = customer.notes | newline_to_br | split: '<br />' %}
{% assign gender = lines[0] | split: ':' %}
{{ gender[1] }}
for the other field
{% assign lines = customer.notes | newline_to_br | split: '<br />' %}
{% assign birthday = lines[1] | split: ':' %}
{{ birthday[1] }}
Remember to mark the solution and like it! 😀
FYI, you cannot access list values with syntax like `line[0]` in Flow.
That said, in this case, you can iterate over that list using a loop or use the tag "first" or "last".
Good point, Paul. I tried with plain liquid, not inside a workflow.
for the case DasolJol was proposing, and as Paul said, something like that should work:
{% assign lines = customer.notes | newline_to_br | split: '<br />' %}
{% assign gender = lines.first | split: ':' %}
{{ gender.last }}
for the other field
{% assign lines = customer.notes | newline_to_br | split: '<br />' %}
{% assign birthday = lines.last| split: ':' %}
{{ birthday.last }}
If you want to add more fields, then the logic will need to change.
Hello,
Thank you for your help!
However, I tried with the code above, it does not work.
It said, "notes" is invalid. So I changed it to "note".
After that, it said "customer.note.last.last" is invalid. Replace this variable.
Could you help me with this error?
This is an accepted solution.
My fault Dasonjong,
In order to access the first and last element, you need to do this:
birthday | last
I've been trying the code and it works fine with the above-mentioned, except that for some reason, shopify adds some extra newlines characters. You will need a way to remove them in order to make this approach to work. for reference:
gender:
{% assign lines = customer.note | newline_to_br | split: '<br />' %}
{% assign gender = lines | first | split: ':' %}
{{ gender | last }}
birthday:
{% assign lines = customer.note | newline_to_br | split: '<br />' %}
{% assign birthday = lines | last | split: ':' %}
{{ birthday | last }}
Hope this helps.
This is an accepted solution.
The tags themselves add newline characters. You can remove them by using hyphens in that tags. For example, this will remove whitespace before and after the opening {% and closing %}
{%- assign lines = customer.note | newline_to_br | split: '<br />' -%}
Thank you so much!
It works!
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024