Limit a Discount to certain Product Variants

Limit a Discount to certain Product Variants

JHdez711
New Member
7 0 0

Is there a way to limit a Shopify-created discount to apply to specific product variants using a mutation in GraphQL? (I'd like to target them by using their variant sku)

Replies 5 (5)

tobebuilds
Shopify Partner
420 28 110

Hi JHdez711,

 

EDIT: Yes, you probably can.

 

Take a look at the `DiscountItemsInput` type in Shopify's GraphQL API:

 

https://shopify.dev/docs/api/admin-graphql/2024-07/input-objects/DiscountItemsInput

 

It only supports `all`, `collections`, or `products`.

 

However, `products` has `productVariantsToAdd` and `productVariantsToRemove` options you can try.

Best,

Tobe

Founder, Regios Discounts app (4.9 stars)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer
JHdez711
New Member
7 0 0

Yeah, I see how that would work. The problem with that I think might be that there are about 5000+ products that I would like this to apply to. I'm trying to target the variants in those products that have a certain color in their SKU ("BL" for blue, "ONG" for orange), and I just don't think gathering all those ids manually is the right move.

tobebuilds
Shopify Partner
420 28 110

If you're already using the API, why do you need to gather the IDs manually? You can use the API to list the variants of all your products, and then use code to filter out the ones that meet your desired criteria.

 

Another alternative you have is to implement a custom discount app using Shopify Functions, which is more flexible, but requires Shopify Plus.

Founder, Regios Discounts app (4.9 stars)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer
JHdez711
New Member
7 0 0

Sorry, still figuring out how all this works but I see what you mean. The store I'm working on is Shopify Plus, but I've gotten stuck working on the custom app side too.
I've been following this discount tutorial and trying to modify it's "quantity" criteria to criteria based on SKU or even variant title:
https://shopify.dev/docs/apps/build/discounts/experience/build-discounts-function

JHdez711_0-1724171031321.png

If you could provide some help on that side of things it would be greatly appreciated.

JHdez711
New Member
7 0 0

Actually, would you happen to know how the mutation would look like if this were the way I would end up going?