The Product Discount API enables you to create a new type of discount that is applied to particular product variants or cart lines. ## Example use cases - Money off a product. For example, 20% off shirts. - Money off a product variant. For example, $5 off blue shirts. - Money off a cart line. For example, 10% off products with a name engraving option. - Buy a specific quantity of a product for a specific amount. For example, $5 off up to 2 blue shirts. - Buy a specific amount of a product, get a second amount at a discount. For example, buy 4 shirts and get 2 blue shirts free. ## Getting started Follow the getting started tutorials to learn how to customize and extend discounts:

Build a product discount function

Create a new "Volume discount" that offers a percentage off when customers purchase more than the minimum quantity of a product.

Build a discount function with an Admin UI extension

Create a discount with an Admin UI extension that allows merchants to create discounts and apply them to orders.

Build a discount UI with Remix

Create a discount UI with Remix that allows merchants to create discounts apply them to orders.

Build a discounts allocator function

Create a discounts allocator function that uses metafields to define custom allocation logic for discounts at the order and cart levels.

## Developer tools and resources

Shopify CLI

A command-line tool for building Shopify apps.

Product Discount API reference

Consult the GraphQL reference for the Product Discount API.

## Migrating from scripts to functions If you want to migrate an existing [line item script](https://help.shopify.com/manual/checkout-settings/script-editor/shopify-scripts) to Shopify Functions, then you can use the following mappings: | Shopify Scripts method | Description | Shopify Functions object | Additional context | | ------------ | ----------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -------------- | | `change_line_price` | Applies a discount to a cart line for a product by specifying a new reduced price, and a message | [Product discount](/docs/api/functions/reference/product-discounts/graphql/functionrunresult) | Apply one or more [Discounts](/docs/api/functions/reference/product-discounts/graphql/common-objects/discount) by specifying the [Value](/docs/api/functions/reference/product-discounts/graphql/common-objects/value) (`percentage` or `fixedAmount` off), [Target(s)](/docs/api/functions/reference/product-discounts/graphql/common-objects/target) (either a `cartLine`, or `productVariant`), and an optional message. | `split` | Splits a product into multiple lines so that you can apply discounts to partial quantities | [Product discount](/docs/api/functions/reference/product-discounts/graphql/functionrunresult) | Use the optional `quantity` field in [Target](/docs/api/functions/reference/product-discounts/graphql/common-objects/target) (either a `cartLine`, or `productVariant`) to optionally limit the number of units the discount may be applied to. | | `change_properties` | Adds or changes a line item property | Not available | Refer to [applyAttributeChange](/docs/api/checkout-ui-extensions/latest/apis) in the checkout UI extensions API to apply attribute changes. | | `reject` | Disallows a discounts code from being applied at checkout | Not available | Use a [Product discount](/docs/api/functions/reference/product-discounts/graphql/functionrunresult) or [Order discount](/docs/api/functions/reference/order-discounts/graphql/functionrunresult) function that contains the necessary logic. For example, you can use conditions to exclude a discount from applying. | ## Limitations and considerations - Input `cart.deliveryGroups` is always an empty array for this function. - Active automatic app discounts using Shopify Functions are applicable for all [Shopify sales channels](https://help.shopify.com/manual/online-sales-channels) that use Shopify Checkout, including the [Online Store](https://help.shopify.com/manual/online-store) and [Shopify Point Of Sale (POS)](https://help.shopify.com/manual/sell-in-person). ## Next steps - Learn how to use Shopify Functions by [building a discounts experience](/docs/apps/build/discounts).