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.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

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
593 42 159

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.8 stars, 93 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer
- Often imitated, never duplicated

View solution in original post

Replies 2 (2)

tobebuilds
Shopify Partner
593 42 159

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.8 stars, 93 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer
- Often imitated, never duplicated
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!