Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Using FLOW to Tag products based on METAFIELDS

Using FLOW to Tag products based on METAFIELDS

TwistyPuzzles
Excursionist
17 0 8

Hey all, Now bear with me i will try to be as clear as I can. 

 

I currently allow the user to filter my collection pages based on the sizes of the products

(Example: 56mm, 57mm, 60mm etc....) 

On each of the product pages i tag the products like "Size_56mm" and thats how that works. 

 

Now, to display the product details to the customer im using Metafields, (one for size, one for weight, one for material/colour etc...). To avoid me duplicating information (putting the size "56mm<sup>3</sup>" in the metafield AND the tags) I would like to make FLOW so that when the product inventory changes it checks to see if the product.metafields.custom.size  contains a value and if it does it would add a tag to that product (I can do that and its easy enough) but the hard bit is getting the value from the metafield and manipulating it into something that can be filtered.

I need to turn the metafield value of "56mm<sup>3</sup>" into "Size_56mm"

Hope all of this makes sense.

Reply 1 (1)

paul_n
Shopify Staff
1433 157 332

So first, I would avoid doing this on inventory change. That is VERY frequent and not necessary as this kind of info shouldn't change that often. 

 

As to the question, there are a lot of ways to do this in liquid. Maybe the easiest way, assuming you have a product metafield and just need "56mm" part is to split by <sup> and take the first value of the list

 

{% assign mf = product.metafields | where: "namespace", "foo" | where: "key", "bar" | first %}
{% assign new_mf = mf.value | split: "<sup>" | first %}
{{ new_mf }}

 You can then use the list to output your string. 

 

 

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.