Order Discount timing - Shopify Functions

Order Discount timing - Shopify Functions

jeffhooton
Shopify Partner
4 0 0

Hey everyone!

I have a situation where a Shopify Plus client of mine wants to offer discounts to users depending on that customer's tags.

 

This is the user journey thus-far:

 

1. Customer lands on "customer lookup page", enters their email address, and then clicks "continue"

2. We redirect the user to blah.myshopify.com/cart/{product-variant-id}:1?checkout[email]={email-address}

3. We land in the checkout flow, on the information step with Email address pre-filled

 

To accomplish the discount portion of this I've created an Order Discount function inside an app. The RunInput of this function pulls the buyerIdentity off of the cart, inside there we grab the customer and their tags. I have some logic that determines whether or not a discount applies for that customer.

 

I then return an object from the run function that contains a discountApplicationStrategy AND an array of discounts.

 

I can tell that the function is running inside my app's extensions page. I see that I receive the correct customer in the RunInput, my logic determines the discount to return, and the discount that I expect is returned from the run function.

 

The issue here is that when users are redirected into a cart, no discount is shown UNTIL they hit the shipping step, in the shipping step I finally see the discount from my Order Discounts function run. Client worry here is that conversion rate is going to tank unless that discount is shown on the first step of checkout, Information.

 

Is there any way to specify when the discount is applied through the function run? Or am I going at this the wrong way?

I'm assuming I can't run any js within the checkout flow or I would just ping an endpoint exposed by my app to run through my discounting logic and then just tweak (fake) the discount in the UI depending on the result.

 

Any help in making sure the discount applies on the very first step of checkout would be greatly appreciated, thank you!


EDIT: if I refresh on the Information step, the discount applies which leads me to believe that it isn't gated behind the contact information being filled out.

Replies 4 (4)

Liam
Shopify Staff
2873 312 820

Hi Jeffhooton,

 

Just to confirm, are you looking to show the discount on the cart page or the first page of 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

jeffhooton
Shopify Partner
4 0 0

Hey Liam - first step of checkout is my goal.

I've found that swapping over to one-page checkout solves the issue (discount from functions run applies upon landing on one-page checkout), but I'd love to give my client the opportunity to choose between one and three page checkout rather than telling them it will only work with one-page checkout.

Liam
Shopify Staff
2873 312 820

I was thinking that the one-page checkout might solve for this, so that's good to hear. Could you add a separate component to the customer info as a checkout UI extension?

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

jeffhooton
Shopify Partner
4 0 0

So client ended up being totally fine with 1-step checkout so that's the route we're going to continue down.

After that I had the app fully working, on checkout it tagged customers correctly, and then an Order Discount function would run to check customer tags and apply a discount if certain criteria was met.

I was getting function run logs in my partners panel extension page for the app until recently.

Now for the life of my I cannot get the function to run whatsoever.

Checking for the function in my development store using Shopify Graphiql I can see that Shopify is registering my function - the id lines up with what I'm seeing on the extension page of the app's dashboard, but on checkout it doesn't run, and I don't get any "runs" inside my partners panel.

When I land on the checkout page I do see a call to `https://{my-store}.myshopify.com/private_access_tokens?id=...` which is returning a 401 error. Through another post on this forum I tried completely uninstalling my app, deleting it, and creating another one for testing with no luck at all.

Any help or ideas on why Shopify appears to be registering my function but it doesn't run at the correct target (`purchase.order-discount.run`) would be greatly appreciated.