Limit a Discount to certain Product Variants

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)

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

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.

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.

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

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

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