Tiered Discount Function Using Tags

I have a large number of 30K products in my store and I have some volume discounts on them.

E.g. Buy (% off)

1-2: Normal price

3-5: 4%

6-10: 6%

11+: 10%

The products are set up with 2 tags. One to identify if the product qualifies for volume discounts, another to specify the tiers. For the above example, this will look like this:

Tags: “volume-discounts”, “vdo|3:4|6:6|11:10”

The tags dont contain the normal price since theyre in the product anyway.

I then do some string split etc to work out the discount percent to apply. The shopify script has been running really well. However, now when Im trying to port this over to a shopify function, I cant see a way to get the product tags. I can filter by productvariant with hasAnyTag: volume-discounts. But how do I access the product tags?

I looked through some posts which talk about input variables and metafields but couldnt quite put it together. I would really appreciate some help here getting access to the tags in my function. Thanks so much!

I looked at setting cart line attributes but being on the frontend, its not secure because it can be manipulated to give greater discounts. I need a way to access the tags directly from the products or another way of securely doing it.

Hi, did you ever figure out how to pull tags in your discount function? The way i have built this out in the past is by assigning a metafield to each product which contains pricing info, for example a product has a base price of $50 and a metafield of “2145|10040” in which 21 is the qty needed to set the price of the product to 45. I then use some logic to to add in a fixed money discount to each product but now for a new project I need to accomplish something similar using tags.

Tags wont work. So I did the exact same as you and migrated all tags to metafields. The solution works really well. Tags dont get to be projected into the function so it wont work. You can only use it to filter.

1 Like