I'm trying to create some custom rules for discount codes, via the Shopify API, and could use some help with this. I've tried support but they could not help.
Imagine the store has 3 products - product A, product B and product C. These would be the conditions for the price rule:
- Discount code applies -100% on 1 unit of product A and 1 unit of product B.
- Discount code only applies if there are at least 1 unit of product A and 1 of product B in the checkout cart.
- If other products (e.g. more units of those 2 or even product C) are added to the cart, those are billed normally and discount does not apply to them.
Is this even possible to implement using the properties of price rules?
Hey @gd_silva, you should be able to create a price rule based on the use case you outline above. Using the PriceRule resource you'd want to set line_items as the "target" value and assign the products you want the discount to apply to as the values for either the "entitled_products" or "entitled_variants" fields after setting the Price Rule's "target_selection" to "entitled".
This would effectively make it so that when a customer applies the discount it would only apply to the specific products and not to any others, like you mentioned in your initial post. Hope this helps - let us know if we can clarify anything on our end for you!
Hi, @ShopifyDevSup, thanks for your response. It put me in the right direction but I'm not still there. Using those options (check the JSON payload below) does not really apply all the conditions I need, since it would apply to any number of units of each of the entitled products.
I'm already using the entitled collection IDs property but I still need to apply the discount to only 1 unit of each of the entitled collections (I have 2, A and B). And the discount should apply to 1 unit of collection A and 1 unit of collection B, even if there are more units of products belonging to those collections in the cart.