Extract specific text from product description to be used as a metafield?

Andyedalus
Visitor
1 0 1

I have a feeling this may not be possible, but figured it may be worth asking anyway. I'm looking to add metafield data that's sourced from info that's already included in a product's description. I deal with disc golf discs and each disc has 4 numbers to represent how it flies, Speed, Glide, Turn, and Fade, which are notated as "X / X / X / X". My product descriptions include a line that reads "Flight numbers: X / X / X / X". I'd like to have each one of those numbers separated out to be attached to the product as a metafield so that customers can use them for filtering.

 

Is there a way to do something like use wildcards to isolate those numbers from the description and save them as the appropriate metafield?

 

The (very) long workaround alternative I'm imagining is changing my descriptions to read something like "Speed: 5, Glide: 4, Turn: -1, Fade: 1" and then a series of flows like "check if... description includes 'speed: 5' --then--> add/update product metafield 'custom.speed' with value 5", but that sounds like many many hours of work and may not be worthwhile compared to simply editing the metafields manually at that point haha.

Reply 1 (1)

paul_n
Shopify Staff
1065 137 253

Hi, this is probably possible using liquid. I might look at "split": https://shopify.github.io/liquid/filters/split/

 

For example:

 

 

{% assign split_description = product.description | split: "Speed: " %}

 

 

 

This would return everything before Speed and then "5, Glide: 4....". So you would need to take the second item in the list and split it again by the comma. And then repeat for each value you want. I think this would return the speed, as long as "Speed:" always exists in the text and there is only 1 of them. 

 

 

{% assign speed = product.description | split: "Speed: " | last | split:"," | first %}
{{ speed }}

 

 

 

 

 

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.