Skip to main content

Discounts API

The API for interacting with discounts.

Support
Targets (31)

Supported targets

  • purchase.checkout.actions.render-before
  • purchase.checkout.block.render
  • purchase.checkout.cart-line-item.render-after
  • purchase.checkout.cart-line-list.render-after
  • purchase.checkout.chat.render
  • purchase.checkout.contact.render-after
  • purchase.checkout.delivery-address.render-after
  • purchase.checkout.delivery-address.render-before
  • purchase.checkout.footer.render-after
  • purchase.checkout.header.render-after
  • purchase.checkout.payment-method-list.render-after
  • purchase.checkout.payment-method-list.render-before
  • purchase.checkout.pickup-location-list.render-after
  • purchase.checkout.pickup-location-list.render-before
  • purchase.checkout.pickup-location-option-item.render-after
  • purchase.checkout.pickup-point-list.render-after
  • purchase.checkout.pickup-point-list.render-before
  • purchase.checkout.reductions.render-after
  • purchase.checkout.reductions.render-before
  • purchase.checkout.shipping-option-item.details.render
  • purchase.checkout.shipping-option-item.render-after
  • purchase.checkout.shipping-option-list.render-after
  • purchase.checkout.shipping-option-list.render-before
  • purchase.thank-you.announcement.render
  • purchase.thank-you.block.render
  • purchase.thank-you.cart-line-item.render-after
  • purchase.thank-you.cart-line-list.render-after
  • purchase.thank-you.chat.render
  • purchase.thank-you.customer-information.render-after
  • purchase.thank-you.footer.render-after
  • purchase.thank-you.header.render-after

The base API object provided to purchase extension targets.

Anchor to discountAllocations
discountAllocations
<[]>
required

The discount allocations applied to the entire cart, including automatic discounts, code-based discounts, and custom discounts from Shopify Functions. Each allocation indicates how much was discounted and how the discount was triggered.

Anchor to discountCodes
discountCodes
<[]>
required

The discount codes currently applied to the checkout. The list is empty if no discount codes have been applied. Use applyDiscountCodeChange() to add or remove codes.

The API object provided to purchase.checkout extension targets.

Anchor to applyDiscountCodeChange
applyDiscountCodeChange
(change: ) => Promise<>
required

Adds or removes a discount code on the checkout. The returned promise resolves when the change has been applied by the server, and the discountCodes property updates with the new state.

Caution

> See security considerations if your extension retrieves discount codes through a network call.

Note

This method returns an error if the cart instruction discounts.canUpdateDiscountCodes is false, or the buyer is using an accelerated checkout method, such as Apple Pay or Google Pay.

Anchor to useApplyDiscountCodeChange
useApplyDiscountCodeChange()

Returns a function to add or remove discount codes.

(change: ) => Promise<>

Anchor to useDiscountAllocations
useDiscountAllocations()

Returns the current discount allocations applied to the cart.

[]

Anchor to useDiscountCodes
useDiscountCodes()

Returns the current discount codes applied to the cart.

[]
Was this page helpful?