Happening now | Office Hours: Customizing Your Theme With Moeed | Ask your questions now!

Delivery Option reset to first when update line item

Delivery Option reset to first when update line item

akshay_joseph
Shopify Partner
13 3 18

We are developing a Checkout UI extension that adds a custom line item. However, when we add the line item through code, Shopify re-renders the shipping method section and automatically selects the first shipping method. How can we retain the previously selected shipping method?

Reply 1 (1)

Dotsquares
Shopify Partner
441 28 59

Hi @akshay_joseph ,

 

When a Checkout UI Extension modifies the cart — such as by adding a custom line item — Shopify's checkout may re-evaluate the available shipping options. This can trigger a re-render of the shipping method section and reset the selected option to the default (usually the first one).

Currently, there’s no direct API method to persist or reapply the previously selected shipping method after cart changes within a Checkout UI Extension.

 

However, here are a few workarounds you might consider:

 

Capture and Reapply (Limited Support):
While you can use the useShippingOptionTarget and useSelectedShippingOption hooks to observe the selected method before the line item is added, there's no supported way to programmatically reapply that selection after the re-render.

 

Minimize Triggering Cart Updates:
If possible, defer adding the custom line item until after the shipping method is finalized, or batch changes together to reduce re-renders.

 

Provide User Feedback:
If a reset is unavoidable, consider alerting users to double-check their shipping method, or guide them back to their previous choice.

 

Hope this will help, Let me know if you need more guidence.

 

Regards,

Dotsquares Ltd


Problem Solved? ✔ Accept and Like solution to help future merchants.


Shopify Partner Directory | Trustpilot | Portfolio