Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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.

How can I Re-run shipping discount function in checkout

Solved

How can I Re-run shipping discount function in checkout

daveelton
Shopify Partner
3 0 0

I have set up a shipping discount function which applies a 100% shipping discount for "members" (users with a tag applied) on my shop. These members should only get to use this perk four times per year, which I'll manage via a DB or metafield, no problems here. The tricky part is we want to allow members the option to opt-out of using one of their free shipping perks for whatever reason, let's say on an especially small order. I have figured out how to use a Checkout UI extension above the shipping methods area to present this option, however, I cannot figure out how to somehow flag the order as waiving free shipping (REST call to the custom app perhaps?), nor can I figure out how I can go about making the shipping discount Function re-run. I'm hoping there is some straightforward way to do this, but have thought of a couple other ideas if not:

 

- We could direct users wishing to waive free shipping to a profile page, where they could toggle off an option (metafield?) on their account, then return to the checkout. This flow redirection should re-trigger the checkout calculations.

- We could create a dummy product called "Waive shipping" that we add or remove from the cart on the checkout page, which presumably would also re-trigger the calculations, but I have not tested this theory.

 

Would love to hear any other "clever" solutions if there really isn't any other way to force a recalculation on the checkout page. Thanks in advance!

Accepted Solution (1)

tobebuilds
Shopify Partner
477 34 128

This is an accepted solution.

Hi Daveelton,


You could try setting a cart attribute when the customer opts out of the shipping discount. I am not totally sure if that will trigger a recalculation of discounts, but it's worth a shot, and would be the most straightforward option.

Best,

Tobe

 

 

Founder, Regios Discounts app (4.9 stars, 68 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer

View solution in original post

Replies 2 (2)

tobebuilds
Shopify Partner
477 34 128

This is an accepted solution.

Hi Daveelton,


You could try setting a cart attribute when the customer opts out of the shipping discount. I am not totally sure if that will trigger a recalculation of discounts, but it's worth a shot, and would be the most straightforward option.

Best,

Tobe

 

 

Founder, Regios Discounts app (4.9 stars, 68 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer
daveelton
Shopify Partner
3 0 0

Thank you! I had actually tried this already, but your comment made me try it again, and I now realize I must have been doing something incorrectly previously. I suspect I may have been setting the attribute value to true/false, where it actually requires a string - this time I awaited the call and logged the response which let me know this was a problem. Anyway, thanks again!