Core Issue:
A developer seeks to access Shopify discount codes/price rules from a Liquid page using JavaScript, attempting to retrieve discount data dynamically on the storefront.
Key Findings:
The Shopify discount object is only accessible in email notifications or the Order Printer app, not within theme templates
Discount information cannot be directly queried from frontend Liquid/JavaScript in the standard theme environment
Proposed Workarounds:
Cookie-based retrieval: Extract discount codes from browser cookies using document.cookie parsing (code snippet provided)
Admin API query: Use an async function to fetch from the Admin API endpoint (admin/price_rules.json), iterate through results, and match by discount code title
Limitations Noted:
The Admin API approach only retrieves manual discount codes, not automatic discounts/price rules
Accessing automatic discounts may require the GraphQL API instead
Status: The discussion remains open regarding how to retrieve automatic discounts, with no complete solution provided for that specific use case.
Summarized with AI on November 16.
AI used: claude-sonnet-4-5-20250929.
Discount object is only accessable in notifications or in Order Print app
The discount object contains information about a discount, including its id, code, amount, savings, and type. Note that this object will display a value only if it’s accessed in notifications or in the Order Printer app.
Old question, but I don’t believe it was ever properly answered. I whipped up this function to be able to query the Shopify API to pull the entire discounts list, iterate through them to search for a specific discount (by discount code) and output the information accordingly. Hope this helps future devs!
Thank you, that works, but if you have automatic discount/price rules they won’t be listed. do you know a way to get the automatic discounts, or is it only possible with the GraphQL api?