Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Hi,
I recently asked about whether it is possible to add adding a tag to metafield after first removing prefix
e.g. brand_adidas tag becomes adidas in metafield.
But what about the opposite.
Is it possible to take the value of a metafield and convert it into a tag with a prefix.
Something like...
- Trigger = product added to store
- Condition = metafield namespace and key matches to metafield we want value of
- Action = add metafield value to tag with prefix (e.g. 'brand_')
e.g.
I list an item and add Adidas to the metafield 'brand'
Once the flow is complete the item should have a tag of 'brand_Adidas'.
Solved! Go to the solution
This is an accepted solution.
Yes, you can do that in liquid. Assuming it's for an order, you would put this (remove any line break) in the tag field.
{% for mf in order.metafields %}
{% if mf.namespace == "custom" and mf.key == "key-name" %}
prefix_{{ mf.value}}
{% endif %}{% endfor %}
This is an accepted solution.
You're a genius. Thank you so much, Paul. That worked!
You've really helped us out there, and in doing so hopefully helped us to make more money for our cause.
Now, just need to decide which of your many solutions is the one to flag as the solution.
For the benefit of anyone else reading this the correct liquid ended up being
{% for mf in product.metafields %} {% if mf.namespace == "product" and mf.key == "letter_size" %} Size: {{ mf.value | replace: ",", ", Size: " | remove: "[" | remove: "]" | remove: '"' }} {% endif %}{% endfor %}
This is an accepted solution.
Yes, you can do that in liquid. Assuming it's for an order, you would put this (remove any line break) in the tag field.
{% for mf in order.metafields %}
{% if mf.namespace == "custom" and mf.key == "key-name" %}
prefix_{{ mf.value}}
{% endif %}{% endfor %}
Hi Paul,
Thanks for this response. I was actually looking for a flow that would work on the product being added to the store.
It doesn't look like the 'add product tags' allows for liquid
You need to hit enter after adding that liquid
That's perfect. Thank you.
It works for that.
I've set it up to also work from a metafield that has a list of set values. example below:
I've used the liquid below for this
{% for mf in product.metafields %} {% if mf.namespace == "my_fields" and mf.key == "category" %} {{ mf.value}} {% endif %}{% endfor %}
The flow works, but has a bit of an issue in that it creates tags that include [ or ] or " in the tag value.
Do you know if there is a way of stripping this out?
Thanks again for all your help. This is going to be really useful stuff for us. we're a charity with lots of people (including volunteers) listing items and we're trying our best to create a way of making the listing process as easy as possible and having as few possibilities for human error as possible.
This is the full flow by the way:
The list type is new to Flow so I'm not terribly familiar with it yet. Based on that screenshot, it looks like it's treating the values as a string and then splitting by the comma(s) because that's what the tag action does to allow multiple tags in one liquid statement. If you want each of those values as a tag, then you should try to remove the quotes and the brackets. Something like this:
{{ mf.value | remove: "[" | remove: "]" | remove: '"' }}
Here's docs on this:
https://shopify.dev/api/liquid/filters#remove
Thanks again.
I'm very nearly there. What you've suggested for stripping out the characters works great.
The flow works great with one small exception.
Where a metafield allows for multiple selections AND should be prefixed when added as a tag the flow will add the prefix to the first metafield value but not any subsequent ones.
e.g. I'm adding a letter size for a cardigan. I used the metafield for this as below
The flow runs as expected and tags are added, but the prefix is added only to S
I have tried the liquid tag action as both the prefix version (A) from above and also as prepend: "Size: " (B)
A - {% for mf in product.metafields %} {% if mf.namespace == "product" and mf.key == "letter_size" %} Size: {{ mf.value | remove: "[" | remove: "]" | remove: '"' }} {% endif %}{% endfor %}
B - {% for mf in product.metafields %} {% if mf.namespace == "product" and mf.key == "letter_size" %} {{ mf.value | prepend: "Size: " | remove: "[" | remove: "]" | remove: '"' }} {% endif %}{% endfor %}
Both variations will give me nearly correct tags but with the "Size: " prefix only added for the first value selected.
Sorry, I know this is a lot to ask, but do you have any idea why that is?
What is the character in that size between S and M? It looks like it's being treated as comma. So when this runs outputs
Size: S, M
The tag action then splits them by the comma so you get "Size: S" and "M".
Assuming you want "Size: S" and "Size: M" I might just replace the comma with ", Size: ". So like this:
{{ mf.value | replace: ",", ", Size: " }}
This is an accepted solution.
You're a genius. Thank you so much, Paul. That worked!
You've really helped us out there, and in doing so hopefully helped us to make more money for our cause.
Now, just need to decide which of your many solutions is the one to flag as the solution.
For the benefit of anyone else reading this the correct liquid ended up being
{% for mf in product.metafields %} {% if mf.namespace == "product" and mf.key == "letter_size" %} Size: {{ mf.value | replace: ",", ", Size: " | remove: "[" | remove: "]" | remove: '"' }} {% endif %}{% endfor %}
User | RANK |
---|---|
3 | |
2 | |
2 | |
2 | |
2 |
Transform this holiday season into a shopping spree. Plus, learn how to effortlessly open ...
By Jasonh Dec 8, 2023Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023