Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Hi,
We use a number of tags with prefixes. Some examples are:
- 'brand_{brand}' , for example 'brand_nike'
- 'size: {size}', for example 'size: 32'
The filtering app we use currently has functionality to recognise the prefix and include everything after it as a filter option. e.g. for brand_nike it would ignore brand_ and just include 'nike'.
We can't move entirely over to just entering metafields for things like this for a number of reasons, so would like to add data to product metafields using flow. Some of this is about our listing integration but also because we can't do away with tags entirely because you can't make a collection based on metafields.
The question is:
Is there a way in Shopify flow to recognise when a certain tag prefix has been added and then add the tag info that follows the prefix into a metafield.
For example:
I add a product to the store with tag of brand_nike
The flow would work like
- Trigger = product added to store
- Condition = product tags include 'brand_'
- Action = add everything after 'brand_' to {metafield}
thanks
Solved! Go to the solution
This is an accepted solution.
Hi Jake,
Yes you can do what you suggested there. I think this would be a useful template in Flow, so we'll create one to show how to do it. Two considerations:
- There is no "product/updated" or "product tag updated" trigger yet in Flow, which means the above will only run at creation time. There is also a "Product status changed" trigger that would fire as it moves from draft to active (and other changes to status). Also, with product added to store, you could manually run that workflow on existing products to backfill the metafields. Go to the admin and choose the products and look under "More actions" for "Run Flow automation"
In the action, you'll need to use liquid to strip the "brand_" part and get the value to add to the metafield value field. Something like:
{% for tag in product.tags %}{% if tag contains "brand_" %}{{ tag | remove: "brand_" }}{% endif %}{% endfor %}
This is an accepted solution.
Hi Jake,
Yes you can do what you suggested there. I think this would be a useful template in Flow, so we'll create one to show how to do it. Two considerations:
- There is no "product/updated" or "product tag updated" trigger yet in Flow, which means the above will only run at creation time. There is also a "Product status changed" trigger that would fire as it moves from draft to active (and other changes to status). Also, with product added to store, you could manually run that workflow on existing products to backfill the metafields. Go to the admin and choose the products and look under "More actions" for "Run Flow automation"
In the action, you'll need to use liquid to strip the "brand_" part and get the value to add to the metafield value field. Something like:
{% for tag in product.tags %}{% if tag contains "brand_" %}{{ tag | remove: "brand_" }}{% endif %}{% endfor %}
Here's a link to the template: https://shopify.com/admin/apps/flow/web/editor/templates/908286d2-3e4c-4d9d-8e28-3cf9b12db4df
If that doesn't work, look for the one titled, "Update a product metafield if a product tag has a certain prefix"
Hi Paul,
I have been attempting to get this flow working on my store, but I keep getting this error- Got error updating metafield: "Value must be a single line text string." For value: " "
I contacted Plus support earlier today but they couldn't figure it out and had to submit a ticket to the flow team. This Flow would save me HUUUUUUUUGGGGGGEEEEE amounts of time. I would really love to get this up and running.
Hi @floridagifts
I'm no great expert but I was able to get this one working.
Are you able to copy in the flow here (screenshots or copying the logic of the step that isn't working) and I'm happy to take a look.
Full disclosure though, I'm actually looking to move in the opposite direction. i.e. we set up metafields with set options that limit the chance of human error. we then have a flow that instead of creating the metafield form a tag creates a tag from the metafield.
I've got that one working too and for our use case is a better way round of doing it.
@floridagifts wrote:
Hi Paul,
I have been attempting to get this flow working on my store, but I keep getting this error- Got error updating metafield: "Value must be a single line text string." For value: " "
I contacted Plus support earlier today but they couldn't figure it out and had to submit a ticket to the flow team. This Flow would save me HUUUUUUUUGGGGGGEEEEE amounts of time. I would really love to get this up and running.
This means the value that you are putting into the metafield value was an empty string or white space. What liquid are you using in that value field?
Hi Paul,
I'm also experiencing an error when trying to use the 'Update a product metafield if a product tag has a certain prefix' Flow template.
All I have done is change the trigger to "Start when: Product status updated" and then "Check if: Tags starts with brand_".
In the "Update product metafield" action I have:
Metafield namespace: custom
Metafield key: brand
Value: {% for tags_item in product.tags %}{% if tags_item contains "brand_" %}{{ tags_item }}{% break %}{% endif %}{% endfor %}
Type: Single line text
When the Flow runs, I get the following error: Got error updating metafield: "Value must be a single line text string." For value: " "
I'm sure that I must be missing something super simple for it to be suggesting that there is a blank somewhere (or data missing), but I have struggled to find any documentation to try and help me along with this. Please could you kindly advise?
For a Flow template that requires a bit more input than the usual triggers and conditions it would be really helpful to newcomers to metafields (such as myself) if there could be a few more pointers or guidance available. We're hoping to move away from tags and over to metafields in the coming months and getting this Flow to work would be a great step in the right direction.
Thanks for your help.
Try:
{% for tags_item in product.tags %}{% if tags_item contains "brand_" %}{{- tags_item -}}{% break %}{% endif %}{% endfor %}
The hyphens remove whitespace (including new lines). It's also possible that this metafield requires a value. If so you might need to add a condition to check for when no tags match and then add a value like "no_brand"
Hi Paul, I really appreciate you getting back to me regarding this. I've tried the updated code, but unfortunately I get the same error message of "Value must be a single line text string." For value: " "
It's worthing noting that I'm testing this Flow using a single product that I know meets the criteria (i.e. it has a "Brand_..." tag) and so it meets the requirements for the Update product metafield action to be run. I'm simply changing the product's status each time the Flow is modified in order to trigger the Flow and hopefully get a successful result that can then be applied to the rest of our catalogue, but no luck just yet unfortunately!
Thanks again and, if you have any other suggestions, please let me know.
Sorry, thinking about this more, the previous suggestion helps but the wrong issue. Here, you don't have any tags at all, so it won't even get to the part with it tries to output the tag. You might need to share a picture of the whole workflow to troubleshoot further because something is happening elsewhere.
Hi Paul, thank you for your help.
Please see the screenshot below. I have installed the "Update a product metafield if a product tag has a certain prefix" template, replaced 'prefix_' with 'brand_' in the "Check if..." box, entered the relevant Metafield Namespace and Key date, and then replaced 'prefix_' with 'brand_' within the liquid code within the Value box.
Changing the status of a suitable product then results in the Flow being triggered, it successfully completes the "Check if..." stage but then provides the following error when it reaches the "Update product metafield" stage: ""Value must be a single line text string." For value: " ""
Thanks again.
I can't tell much from that, but I created a support ticket. Please share a link to the workflow run where you are seeing that message. The support ticket should get routed to me.
Just following up here from a DM, the issue I believe is that liquid conditions and text are case sensitive, whereas Flow conditions are not. So "Brand_" was passing the condition check for "brand_" but not the liquid check for {% if tag contains "brand_" %}. The solution is to use the exact case or cast it to all uppercase or lowercase.
Hello 👋,
It's been some time but this might still be needed by someone else.
We've just launched our app "Copytag - Tags to metafields". It simply copies product tags to metafields. Groups and jobs can be defined by prefixed tags and they can be running automatically.
Here is a link to the app: https://apps.shopify.com/copytag.
And here is a short preview of what it does: https://www.youtube.com/watch?v=Y3z1CuRv1uY.
Don't hesitate to contact us at hey@bigstart.io if you have any questions for the app.
I've just found out that this now also works with the Flow template "Convert tags with a prefix to a product metafield using the Run code action".
Then you don't even need an app 🙂
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024