How can I tag an order with a customer metafield value?

Solved

How can I tag an order with a customer metafield value?

raym1
Visitor
2 0 1

Hey hey, I'm trying to make a flow :
- When a new order is created , the order to be tagged with a Customer Metafield value. 

Currently trying the following ,and although on the flow app it says that it's successful, the tag with the metafieled value is not added on the order. 

I currently use :

  • {% for metafields_item in order.customer.metafields %} {if {metafields_item.namespace=="namespace" and metafields_item.key == "key" }},{ mf.value }{% endfor %}

 

Accepted Solution (1)

ethansz
Shopify Staff
2 2 1

This is an accepted solution.

Hi Raym1, there are a few issues in the code snippet you shared:

  • the mf.value is invalid. "mf" should match the variable used in the rest of the liquid code to output a variable.
  • the end if statement is missing after the metafield value
  • There are some inconsistencies with the liquid syntax

 

So the liquid code should look like this:

 

{% for metafields_item in order.customer.metafields %} 
{% if metafields_item.namespace == "namespace" and metafields_item.key == "key" %}
{{metafields_item.value}}
{% endif %}
{% endfor %}

 

 Just make sure to swap out the namespace and key to match the metafield you want to add as a tag.

Hope this helps!

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 3 (3)

ethansz
Shopify Staff
2 2 1

This is an accepted solution.

Hi Raym1, there are a few issues in the code snippet you shared:

  • the mf.value is invalid. "mf" should match the variable used in the rest of the liquid code to output a variable.
  • the end if statement is missing after the metafield value
  • There are some inconsistencies with the liquid syntax

 

So the liquid code should look like this:

 

{% for metafields_item in order.customer.metafields %} 
{% if metafields_item.namespace == "namespace" and metafields_item.key == "key" %}
{{metafields_item.value}}
{% endif %}
{% endfor %}

 

 Just make sure to swap out the namespace and key to match the metafield you want to add as a tag.

Hope this helps!

To learn more visit the Shopify Help Center or the Community Blog.

raym1
Visitor
2 0 1

Appreciate your response Ethansz. 
However, although the recent runs on the flow app say have the status: succeeded ,no tags are created on the order from the desired customer metafield value. Screenshot - 2024-02-19T151505.138.png 

paul_n
Shopify Staff
1717 188 395

You have a typo...it should be {{metafields_item.value}} not {{ metafield.value}}

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.