Allow for Discount Code to be available in the RunInput Query #574
Replies: 1 comment
-
For anyone interested, I was able to get a Shopify Front End Dev. to opine on this topic. Here is his response: Thank you for taking the time to speak with us and for clearly outlining your current use case around Shopify Scripts and the challenges you're encountering while migrating to Shopify Functions. I’ve reviewed your store setup, the current script implementation, and the goals you’re trying to achieve with your tiered BOGO-style discounts that conditionally run depending on whether a specific discount code is entered. After thorough review, I can confirm that the core limitation you're encountering is due to the fact that Shopify Functions currently does not expose discount code values in the function input payload. While Shopify Scripts allowed conditional logic using Input.cart.discount_code to evaluate whether a particular code was present and respond accordingly, Shopify Functions does not yet offer the same level of detail. This means functions cannot distinguish between which discount code was applied or whether one has been removed, and the stacking logic is currently limited to an all-or-nothing approach. This limitation in Shopify Functions—specifically the inability to detect which discount code was entered—is not an oversight, but rather a deliberate design decision made by Shopify’s product and engineering teams during the architecture of the new checkout extensibility platform. Unlike Shopify Scripts, which run within the same environment as the checkout and have access to real-time cart state and all applied discount codes, Shopify Functions are designed to be stateless, secure, and deterministic. They are executed in a highly optimized, isolated environment with strict input and output contracts. This allows Shopify to guarantee millisecond-level execution, improved checkout performance, and better scalability across millions of checkouts per minute, especially on Plus stores during high-traffic events like Black Friday. Allowing Functions to access the raw discount code string or rely on mutable checkout state (such as the customer adding or removing a code during the flow) would introduce non-determinism. That could lead to unexpected behavior if discount logic depended on user interaction patterns that vary across devices or regions. By removing that variability, Shopify ensures consistent results across the entire checkout experience, which is critical for maintaining trust and performance in a global ecommerce platform. Additionally, Shopify is moving toward separating presentation logic (what the customer sees) from decision logic (how discounts apply), with checkout UI extensions being the interface layer, and Functions acting strictly as compute logic. This separation of concerns is key to supporting long-term stability, especially as more of checkout becomes customizable via public APIs and extensions rather than backend code execution. In essence, the current limitation is part of a broader goal: to build a faster, safer, and more extensible checkout platform for the future. While it does mean some use cases need to be reimagined with different tools or patterns, it also unlocks new capabilities such as stackable function-generated discounts, internationalization support, and fully decoupled checkout components—all of which were difficult or impossible with Shopify Scripts. While there is no native workaround within the Shopify Functions framework, some merchants have implemented partial workarounds by using cart attributes, order metafields, or custom app logic to track discount-related behavior. These are not as reliable or secure as Script-level validation, and they tend to add unnecessary complexity. If you're comfortable working with deeper custom development, it may be worth working with a Shopify Partner who specializes in Checkout UI Extensions and the Shopify Admin API to explore options such as tracking discount codes manually via custom fields or building a post-purchase validation flow. Agencies like Half Helix, Lucid Fusion, or Disco Labs have strong experience in these areas and may be able to help design a custom solution that meets your specific requirements. As a workaround, you may consider breaking up your offer logic across multiple functions with distinct discount configurations. For example, a tiered discount could be set to only run when no other discounts are applied, while a separate automatic discount could handle alternative percentage-based offers. While this doesn’t allow for exact conditional control based on the discount code, it does provide separation and avoids overlap. For merchants looking to maintain more granular control, some are now leveraging Checkout UI extensions or custom app proxies to create a decision layer before discount codes are applied. One approach is to use a Checkout UI extension to inject a field or selector for customers to choose which discount they want to apply, and then store that selection in a cart attribute. The Function can then read that attribute to determine how to apply or withhold the discount. For example, if a customer selects “BOGO Offer,” a cart attribute such as discount_type: bogo can be passed in and used within the function input to gate logic. This won’t catch customers who use the built-in discount code box without interacting with the extension, so it’s not an exact substitute, but it may provide a near-equivalent experience when combined with clear communication and UI changes. Another viable path is to shift part of the promotional logic upstream to the product or cart level. Apps like Shopify Bundles or Rebuy can help present BOGO-type logic before checkout, giving customers the option to choose between offers earlier in the funnel. Additionally, third-party apps such as Discount Ninja or Ultimate Special Offers offer enhanced control over discount stacking, exclusions, and conditional logic without requiring backend development. These tools may allow you to recreate some of your previous Script behavior while leveraging Shopify's newer checkout extensibility platform. |
Beta Was this translation helpful? Give feedback.
-
We are trying to migrate over our Shopify Scripts to Functions and have solved most of our use cases except 1. Currently, if a customer enters a specific discount code at checkout our Script will not run. When the customer removes the discount code, the script is executed. Note that for some discount discount codes we do offer the ability to stack against our shopify discount function but specific discount codes need to be excluded and customers should be able to choose to use the function discount or the discount code.
We have read through all the documentation and looked at various threads and cannot seem to find a solution to this use case.
Beta Was this translation helpful? Give feedback.
All reactions