About discounts
Discount apps integrate with the Shopify admin to provide discount types for app users. This guide introduces the ways that you can extend your app code into Shopify checkout and customize the discount experience.
- Use the GraphQL Admin API to create and manage discounts that are native to Shopify.
- Use Shopify Functions to extend your app code into Shopify checkout and create discount functionality that isn't offered out of the box with Shopify.
Build with the GraphQL Admin API
Anchor link to section titled "Build with the GraphQL Admin API"The GraphQL Admin API enables you to create and manage Shopify discounts.
Discount methods
Anchor link to section titled "Discount methods"You can create discounts that are either applied automatically, or applied with discount codes.
The following table describes the different discount methods you can use as part of your app using the GraphQL Admin API:
Discount method | Description | Example use cases |
---|---|---|
Automatic discount | A discount that's automatically applied at checkout and on a cart if prerequisites are met. | |
Code discount | A discount that customers can redeem using a specific code. Merchants can create and share discount codes individually with customers. |
Visit the Shopify Help Center to learn about the limitations and considerations that apply to each discount type:
Access scopes
Anchor link to section titled "Access scopes"To use discount-related GraphQL mutations when building with the GraphQL Admin API, your app needs to request the following access scopes for a Shopify store:
Access scope | Required or optional? | Description |
---|---|---|
write_discounts |
Required | Allows apps to create and update Shopify discounts |
read_customers |
Optional | Allows apps to query a store's customers |
read_products |
Optional | Allows apps to query a store's products |
read_shipping |
Optional | Allows apps to query the countries that a store ships to |
Build with Shopify Functions
Anchor link to section titled "Build with Shopify Functions"Shopify Functions enable you to create discount functionality that isn't offered out of the box with Shopify. For example, a discount function can be used to create volume discounts with different discount rates upon hitting specified volume breakpoints.
An app developer creates and deploys an app with a function that defines a new discount type. A user can then install the app on a Shopify store and create a new discount from a discount type provided by the app. Shopify executes the function to calculate the discount when a customer adds a product to their cart.
Discount classes
Anchor link to section titled "Discount classes"Discount classes are similar to native discount types. You can create one or more discount classes as part of your app using Shopify Functions.
The following table describes the different discount classes in detail:
Discount class | Description | Example use cases |
---|---|---|
Order discount | A discount that's applied to all merchandise in the cart. |
|
Product discount | A discount that's applied to a particular product or product variant in the cart |
|
Shipping discount | A discount that's applied to one or more shipping rates at checkout |
|
Related mutations and queries
Anchor link to section titled "Related mutations and queries"Explore the following resources to manage discounts in your app. Use mutations to craft, modify, and remove discounts, and use queries to retrieve detailed listings.
Automatic discount mutations
Anchor link to section titled "Automatic discount mutations"The following table outlines some common mutations for creating, updating, and deleting automatic discounts:
Discount type | Mutations |
---|---|
Buy X Get Y or Spend X Get Y |
discountAutomaticBxgyCreate discountAutomaticBxgyUpdate discountAutomaticDelete |
Percentage or fixed amount |
discountAutomaticBasicCreate discountAutomaticBasicUpdate discountAutomaticDelete |
Free shipping |
discountAutomaticFreeShippingCreate discountAutomaticFreeShippingUpdate discountAutomaticDelete |
App |
discountAutomaticAppCreate discountAutomaticAppUpdate discountAutomaticDelete |
Code discount mutations
Anchor link to section titled "Code discount mutations"The following table outlines some common mutations for creating, updating, and deleting code discounts:
Discount type | Mutations |
---|---|
Buy X Get Y or Spend X Get Y |
discountCodeBxgyCreate discountCodeBxgyUpdate discountCodeDelete |
Percentage or fixed amount |
discountCodeBasicCreate discountCodeBasicUpdate discountCodeDelete |
Free shipping |
discountCodeFreeShippingCreate discountCodeFreeShippingUpdate discountCodeDelete |
App |
discountCodeAppCreate discountCodeAppUpdate discountCodeDelete |
Bulk actions |
discountCodeBulkActivate discountCodeBulkDeactivate discountCodeBulkDelete |
The following table outlines some common queries for interacting with automatic and code discounts.
Discount type | Queries |
---|---|
Automatic discounts | automaticDiscountNode automaticDiscountNodes |
Code discounts | codeDiscountNode codeDiscountNodes |
Admin UI extensions vs. Remix App UI
Anchor link to section titled "Admin UI extensions vs. Remix App UI"Developers creating a merchant-facing UI to manage function-powered discounts have the option to use either a UI extension or a Remix App UI. Each method provides distinct advantages and is appropriate for different scenarios.
Admin UI extensions
Anchor link to section titled "Admin UI extensions"Admin UI extensions provide a way to extend the Shopify admin with custom user interfaces built using Shopify’s UI components. This method is great for simpler interfaces that integrate tightly with Shopify’s existing UI.
Benefits:
- The developer is only responsible for building the UI for discount controls that are specific to their discount function (e.g. managing metafield values for discount percentage).
- UI for common discount fields such as active dates, and customer eligibility are provided by the discount page.
- Developers don't need to manage GraphQL requests to create or save discounts because the UI extension integrates with the discount page's save bar when values are updated.
- Shopify hosts the UI code when apps are deployed, so developers don't need to build, deploy, and maintain web servers.
Use Cases:
- Ideal for adding simple form inputs to the discount page to manage quantities and discount amounts for a volume discount app.
Remix App UI
Anchor link to section titled "Remix App UI"Remix app UI allows developers to build dynamic and interactive user interfaces that manage the entire discount details page using the Remix framework. This approach is suited for creating complex discount functionality.
Benefits:
- Developers can customize the entire discount configuration page.
Considerations:
- Involves a higher complexity and a steeper learning curve.
- Involves the developer being responsible for all GraphQL queries and mutations to create and update discounts, including all required fields.
Use Cases:
- Ideal for creating detailed discount pages with custom forms and features as the developer prefers.
By understanding the differences between these two approaches, developers can choose the most appropriate method based on their specific needs and the complexity of the discount functionality they are planning to implement.
Limitations
Anchor link to section titled "Limitations"- The maximum number of automatic app discounts for each store is 25.
- Shopify Functions limitations apply.
Getting started
Anchor link to section titled "Getting started"Follow the getting started tutorials to learn how to customize and extend discounts:
Developer tools and resources
Anchor link to section titled "Developer tools and resources"Explore the following developer tools and resources to learn more about building with Shopify Functions: