Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Apply discount and gift codes in cart page

Apply discount and gift codes in cart page

david-kaplan
Shopify Partner
14 0 2

Dear developers, 

 

 

did anyone find a way to apply discount codes and gift cards prior to checkout page? 

Screenshot 2023-11-12 at 7.37.18 AM.png

My general idea how to do it. 
1. Create a developers app with correct permissions in Shopify admin. 
2. Use Admin API in front end code. 
3. For gift cards list all gift cards, find the code customer put in. If it exists use it. If I understand there is a limit of 250 gift cards. What will happened if there is 251? It will paginate or just ignore the last gift card? Is there an better way to check if the discount is valid? 

4. Check if the code was discount code. How can I check if the discount code is valid? 
5. Apply to cart endpoint. This only solves discount application. How can I apply the gift card? 

Is this a good approach or line of thinking in general? 

Thank you for your answers.  

Replies 4 (4)

Liam
Community Manager
3108 342 884

Hi DKaplos32,

 

What would be the usecase or benefit for applying the discount on the cart versus on the checkout? 

Liam | Developer Advocate @ 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

david-kaplan
Shopify Partner
14 0 2

Hi Liam, thank you for answering. 
The simple answer, my client wants it. 😄 
The longer answer is the following. 
Mostly UX design, conversion, and in general easier communication with customers. 
In the cart, I want to see my real price as close as possible. So applying discount and gift card codes after the customer proceeds to checkout is a little counterintuitive. 

Thank you. 



 

Liam
Community Manager
3108 342 884

Hi again David,

 

Because some discounts are dependant on the info entered at checkout (eg: free shipping discounts, specific customer segments, combinations, etc) it's not super reliable to apply Shopify's native discounting prior to checkout. However you could build a custom solution that could achieve what you're looking to achieve. 

Liam | Developer Advocate @ 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

david-kaplan
Shopify Partner
14 0 2

Liam, 

 

yes you are right I didn't think about this use case. Anyhow the discount code actually works, but the problem is with the gift cards. It shouldn't have issues working prior the checkout. 
Do you have any advice on the gift cards. 

Thank you 🙂