Increase instruction count, query cost and input size
This is becoming a real performance concern for large carts — for example, we’re hitting instruction count limits when the cart contains ~70 line items.
Is there any way to make the appliesOnSubscription: false flag work as expected / is there a Shopify-side fix planned for this issue?
From digging into this, it looks like this is not a bug and it’s expected that you can’t prevent your Shopify Function from executing based on the appliesOnSubscription: false setting alone. The appliesOnSubscription flag is used by Shopify to determine whether a discount should be available for subscription products, but it does not prevent the function from being invoked when subscription items are present in the cart.
This means you must add extra fields to your GraphQL input query to detect subscription lines, and then build logic to your function to skip or filter out subscription lines.
If you’re hitting instruction count limits, you may need to optimize your function logic as much as possible, or look into splitting the logic into multiple functions if possible.
appliesOnSubscription: false currently does not stop a DiscountCodeApp or DiscountAutomaticApp Function from being executed. It only prevents the discount from being applied, not the Function from running. That’s why your Function still triggers when subscription items are in the cart.
Right now, the only reliable workaround is exactly what you’re doing detecting subscription items inside the Function via sellingPlanAllocation. Unfortunately, there’s no Shopify-side fix available yet, and no way to prevent the Function from executing at the platform level.
If performance is a concern for large carts, the best approach is to minimize the input query and simplify subscription checks until Shopify updates this behavior.
Hi folks, update here: Shopify has now shipped purchase-type filtering enforcement for app discounts.
`appliesOnSubscription` and `appliesOnOneTimePurchase` are now enforced at checkout for `DiscountCodeApp` and `DiscountAutomaticApp`.
That means you should no longer need to manually filter subscription or one-time purchase lines only to prevent the discount from being applied to the wrong purchase type.
One clarification: these fields do not prevent the Shopify Function from being invoked. The Function may still run for the cart, but Shopify now filters out targets that don’t match the discount’s configured purchase type before the discount is applied.