Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I've been having quite a few issues with this type of function. The most pressing one right now is that it doesn't seem like I can decide which line items to display the discounts on.
None of my discounts should apply to subscriptions, and I can exclude them from the quantity. The problem is I can't select specifically the variants with no subscription plan in the cart because they all have the same id. So if I have the same product with and without sub it will randomly decide which products to apply it on. How can I effectively exclude subscription lines from the discount?
For example:
4 of Product X with no subs = 25% off
3 of Product X with 30 day sub = no discount
1 of Product X with 14 day sub = no discount
What happens right now is something like:
2 of Product X with no subs = 25% off
2 of Product X with no subs = no discount
1 of Product X with 30 day sub = 25% off
2 of Product X with 30 day sub = no discount
1 of Product X with 14 day sub = 25% off
Hi Ryoshin,
The issue you're encountering is a common one in where a single product has multiple variants with different subscription plans or no subscription at all. You want to apply a discount to only one variant of this product, but currently, the discount is applied randomly to any variant of the product.
Unfortunately, Shopify's discount management system doesn't provide an out-of-the-box solution for specifying which variant of a product should receive the discount. This is because Shopify considers the product as a whole when applying discounts, not the specific variants.
One possible workaround could be to use the Admin API and scripting capabilities to create a more sophisticated discount logic, eg:
Identify the Subscription Variants: Using the ProductVariant object with the sellingPlanGroupCount field, you can identify the product variants that are associated with a subscription plan. This will let you know which variants should not receive the discount.
Create Custom Logic for Discounts: After identifying the subscription variants, you can create a custom script to apply discounts only to the non-subscription variants of a product. This script can run whenever a customer adds a product to their cart.
Apply the Custom Discount Logic: the script to apply your custom discount logic. This script can be triggered when a product is added to the cart or when the customer checks out.
Would an approach like this work for your use case?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
I'm not sure what you mean by scripts. Do you mean the function script or shopify scripts which are being deprecated? If it's shopify scripts I did install it on a dev and live stores before it being removed from the store, but would it be a good approach given it's being deprecated?
Right now I can identify which variants are being purchased with and without sub, and I can adjust quantity adequately, but it displays randomly to the customer. So if 3 should be discounted it may show 2 no subs and 1 sub as discounted when all 3 should be no subs.
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024