Skip to main content

Discount Function Settings API

Requires the function settings component.

The Discount Function Settings API lets you build UI extensions that provide custom configuration interfaces for discount functions. Use this API to create settings pages for Shopify Functions that implement discount logic.

  • Discount configuration: Build settings interfaces for discount Shopify Functions.
  • Metafield storage: Store discount function configuration in metafields with proper validation.
  • Settings UI: Create custom configuration experiences for discount logic and rules.
  • Function integration: Configure Shopify Functions that implement custom discount behavior.
Support
Targets (1)

The shopify global object provides access to discount function configuration and settings. Access the following properties on shopify to interact with the current discount function context in the admin.discount-details.function-settings.render target.

Anchor to applyMetafieldChange
applyMetafieldChange
required

Updates or removes metafields that store discount function configuration. Use this to save merchant settings for your discount function.

required

Provides methods for authenticating calls to your app backend. Use the idToken() method to retrieve a signed JWT token that verifies the current user's identity for secure server-side operations.

required

The discount being configured and its associated metafields storing function settings.

Anchor to discounts
discounts
required

The discounts object provides reactive access to discount configuration, including discount classes and the discount method. Use the signals to read current values and the update functions to modify discount classes in your settings UI. These values automatically update when changed by the merchant or system.

Anchor to extension
extension
{ target: ; }
required

The identifier of the running extension target. Use this to determine which target your extension is rendering in and conditionally adjust functionality or UI based on the extension context.

required

Utilities for translating content according to the current localization of the admin. Use these methods to provide translated strings that match the merchant's language preferences, ensuring your extension is accessible to a global audience.

Anchor to intents
intents
required

Provides information to the receiver of an intent. Use this to access data passed from other extensions or parts of the admin when your extension is launched through intent-based navigation.

Anchor to navigation
navigation
required

Navigates to other extensions or admin pages. Currently supports navigation from a block to an action extension on the same resource page. For example, navigate from a product details block (admin.product-details.block.render) to a product details action (admin.product-details.action.render).

Anchor to picker
picker
required

Opens a custom selection dialog with your app-specific data. Use the Picker API to define the picker's heading, items, headers, and selection behavior. Returns a Promise that resolves to a Picker object with a selected property for accessing the merchant's selection.

Anchor to query
query
< = unknown, Variables = { [key: string]: unknown; }>(query: string, options?: { variables?: Variables; version?: Omit<, "2023-04">; }) => Promise<{ data?: ; errors?: []; }>
required

Executes GraphQL queries against the GraphQL Admin API. Use this to fetch shop data, manage resources, or perform mutations. Queries are automatically authenticated with the current user's permissions. Optionally specify GraphQL variables and API version for your query.

Anchor to resourcePicker
resourcePicker
required

Opens the resource picker modal for selecting products, variants, or collections. Returns the selected resources when the user confirms their selection, or undefined if they cancel.

Anchor to storage
storage
required

Provides methods for persisting data in browser storage that is scoped to your extension. Use this to store user preferences, cache data, maintain state across sessions, or save temporary working data. Storage is persistent across page reloads and isolated per extension.


  • Check operation result type: applyMetafieldChange returns { type: 'success' } or { type: 'error', message: string }. Errors don't throw exceptions, so always check the returned type property.

  • Metafields are subject to size limits. Individual metafield values can't exceed 256KB, and total metafields per resource have storage limits.
  • The applyMetafieldChange method is sequential. Operations are processed one at a time. Rapid successive calls may lead to race conditions where later updates overwrite earlier ones.
  • Metafield changes are applied immediately. Unlike some admin forms, metafield changes persist right away without waiting for the merchant to save the discount.

Was this page helpful?