How can I easily apply discount codes via an app?

Solved

How can I easily apply discount codes via an app?

bishpls
Shopify Partner
26 6 21

Discount Code application from an app is...to put it mildly, problematic.

 

As far as I can tell, there are two ways that definitely work for a public app to add a DiscountCode to a purchase, without requiring the user to manually enter the code at checkout: 

 

1. Query string application / URL redirection

 

2. The Storefront API (https://shopify.dev/api/storefront/2022-01/mutations/checkoutDiscountCodeApply)

 

As well as possibly editing an Order from the Admin API, except that requires taking over the Order creation process from the store. Not ideal!

 

Now, the Storefront API is locked behind converting your app to a sales channel -- a very significant functionality change, and a process that isn't even viable for public apps that already have installed users--meaning literally the only viable method appears to be query string redirects.

 

This seems like EXTREMELY basic functionality that should be part of the AJAX Cart API: https://shopify.dev/api/ajax/reference/cart; it's a very negative user experience to force them through a page redirect / refresh JUST to apply a Discount Code, and a negative (and brittle) merchant experience to inject theme code modifications to adjust the query string for checkout URL(s). 

Accepted Solution (1)

bishpls
Shopify Partner
26 6 21

This is an accepted solution.

fetch(`/discount/${DiscountCode}`)

 

This is the answer, shoutout to Landon Fuhr#2944 for pointing it out. No idea why this isn't documented anywhere!

View solution in original post

Reply 1 (1)

bishpls
Shopify Partner
26 6 21

This is an accepted solution.

fetch(`/discount/${DiscountCode}`)

 

This is the answer, shoutout to Landon Fuhr#2944 for pointing it out. No idea why this isn't documented anywhere!