Headless commerce and custom storefronts with Shopify APIs and SDKs
To continue receiving payouts, you need to secure your account by turning on two-step authentication. If two-step authentication is not turned on your payouts will be paused. Learn more
Hello everyone!
I'm working on one of our clients shops where we use the Shopify Storefront API to interact with the checkout. I have some questions regarding how discounts are handled via the Storefront API:
1. According to the documentation, the Checkout object (https://shopify.dev/api/storefront/reference/checkouts/checkout) has a connection for discountApplications (https://shopify.dev/api/storefront/reference/checkouts/discountapplication).
As far as I understand there is no title/code field on the DiscountApplication Object.
Is it possible to get the title/code of submitted discounts for the checkout? I need these information to show the customer what discounts are active for the checkout.
2. Regarding the documentation the is a mutation to remove discounts from the checkout: https://shopify.dev/api/storefront/reference/checkouts/checkoutdiscountcoderemove
This will remove *all* discounts from the checkout. Is there a way to remove a specific discount?
I appreciate any help 🙂
Solved! Go to the solution
This is an accepted solution.
Hey @marm_alex,
Have you seen the code property on the DiscountCodeApplication object?
You should be able to use a fragment on the checkout's discountApplications (i.e. ... on DiscountCodeApplication) to query the applied discount codes. Here's an example:
{
node(id: "Z2lkOi8vc...kxZjM=") {
id
... on Checkout {
id
ready
discountApplications(first: 5) {
edges {
node {
... on DiscountCodeApplication {
allocationMethod
applicable
targetType
targetSelection
code
value {
... on MoneyV2 {
amount
currencyCode
}
}
}
}
}
}
}
}
}
and the response:
{
"data": {
"node": {
"id": "Z2lkOi8vc...kxZjM=",
"ready": true,
"discountApplications": {
"edges": [{
"node": {
"allocationMethod": "ACROSS",
"applicable": false,
"targetType": "LINE_ITEM",
"targetSelection": "ALL",
"code": "TESTCODE-15OFF",
"value": {}
}
}]
}
}
}
}
Regarding your second point - it isn't possible to remove only one specific discount.
CalD | Developer Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
This is an accepted solution.
Hey @marm_alex,
Have you seen the code property on the DiscountCodeApplication object?
You should be able to use a fragment on the checkout's discountApplications (i.e. ... on DiscountCodeApplication) to query the applied discount codes. Here's an example:
{
node(id: "Z2lkOi8vc...kxZjM=") {
id
... on Checkout {
id
ready
discountApplications(first: 5) {
edges {
node {
... on DiscountCodeApplication {
allocationMethod
applicable
targetType
targetSelection
code
value {
... on MoneyV2 {
amount
currencyCode
}
}
}
}
}
}
}
}
}
and the response:
{
"data": {
"node": {
"id": "Z2lkOi8vc...kxZjM=",
"ready": true,
"discountApplications": {
"edges": [{
"node": {
"allocationMethod": "ACROSS",
"applicable": false,
"targetType": "LINE_ITEM",
"targetSelection": "ALL",
"code": "TESTCODE-15OFF",
"value": {}
}
}]
}
}
}
}
Regarding your second point - it isn't possible to remove only one specific discount.
CalD | Developer Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hello @CalD . Thanks for your answer. The first part helped me a lot! I just overlooked the "code" part in the documenation. Thanks for the hint!
To the second part: Are there any plans to allow to remove specific discounts via API in the future?
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022