Re: Add an Order Tag from a Customers Metafield Value

Add an Order Tag from a Customers Metafield Value

Plasmid
Shopify Partner
5 0 1

I would like to run a flow that adds a customer metafield value as a order tag. Currently I have the below as the rule, but it is not working.

 

Start when...Order Created

Do this... Add order tags

Add the following order tags:

{% for mf in order.customer.metafields %} {% if mf.namespace == 'global' and mf.key == 'slspsn_name' %} {{ mf.value }}{% endif %}{% endfor %}

 

Any advice for an edit to make this work?

Replies 7 (7)

paul_n
Shopify Staff
1167 143 275

What is not working? Have you looked at the workflow run? Is there an error or are you not seeing the tag? Things I'd look at:

  • Does the order have a customer?
  • Does the customer have that metafield?
  • Are there any errors in the run?
  • When you open Add order tags do you see that code ? You might not have pressed enter to add it
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.
Plasmid
Shopify Partner
5 0 1

All orders have customers, and the ones with errors have the specific metafield filled out. 

The error is "Order tags is invalid".

Here are some screenshots of the most recent error, the order # and the metafield for the customer.

Screenshot 2023-04-10 at 10.35.23 AM.png

Screenshot 2023-04-10 at 10.40.45 AM.png

Screenshot 2023-04-10 at 10.42.26 AM.png

Screenshot 2023-04-10 at 10.46.40 AM.png

  

paul_n
Shopify Staff
1167 143 275

Tags has limitations based on length and type of characters allowed. Does that salesperson name have any characters in it? Or is it long?

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.
Plasmid
Shopify Partner
5 0 1

Its long with a phone number and email address - I just tried manually adding it and got an error. ill try another metafield thats more simple - thank you!

paul_n
Shopify Staff
1167 143 275

Cool, you can use liquid to find-and-replace or truncate the text, if needed. 

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.
Plasmid
Shopify Partner
5 0 1

Hey Paul

 

Lets say the full metafield value is "John Doe 555-555-5555 name@email.com"

Is it possible to change the tag to say something different? If metafield is above, than tag "JOHDOE" 

If metafield = "Jack Black 555-555-5555 name@email.com"

Tag order with "JACBLA"


Would the tag code look something like this? Please correct if its wrong...

 

{% for mf in order.customer.metafields %} {% if mf.namespace == 'global' and mf.key == 'slspsn_name'  and mf.value == 'John Doe 555-555-5555 name@email.com' %} {{ JOHDOE }}{% endif %}{% endfor %}
{% for mf in order.customer.metafields %} {% if mf.namespace == 'global' and mf.key == 'slspsn_name'  and mf.value == 'Jack Black 555-555-5555 name@email.com' %} {{ JACBLA }}{% endif %}{% endfor %}

 

paul_n
Shopify Staff
1167 143 275

You could split by spaces and then output the first two items for the name. Something like: 

{% assign names = mf.value | split: " " %}
{% for name in names %}
{% if forloop.counter <= 2 %}{{ name }}{% 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.