Add a discount code to an order?

Highlighted
Tourist
13 0 0

We want to add functionality that allows a customer to add/apply their discount code on the site (i.e., prior to gettng to Shopify's checkout page). 

How do we go about adding the code to the order via Ajax (not GraphQL)?

How we we then retreive that? I ask because we experimented with discount code via URL. That works. The discount gets applied once we get to the checkout. But prior to checkout it didn't seem to beon the orders object, or did we miss something?  

0 Likes
Highlighted
Shopify Partner
2294 116 352

Discounts technically exist on individual line items not orders.

Orders don't exist until an order is created(finishes checkout, draft order)

What a customer has is line items in a cart, then a checkout, then an order ,then a fulfillment


@mfs-mindsize wrote:

How do we go about adding the code to the order via Ajax (not GraphQL)?


Use the parameter ?discount=

https://shopify.dev/tutorials/develop-theme-discounts

https://shopify.dev/docs/themes/liquid/reference/objects/discount-allocation

https://shopify.dev/docs/themes/liquid/reference/objects/discount-application

 

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
1 Like