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 do I add packaging weight dynamically

How do I add packaging weight dynamically

daveelton
Shopify Partner
3 0 0

The store I am working on has a business rule such that for every 42 pounds of product that is ordered, we need to add an additional 8 pounds of weight to cover dry ice and gel packs. The solution I landed on is to hijack the theme's checkout button to prevent form submission, request the cart data to calculate the weight, and then update the cart with the required quantity of a packaging line item weighing 8 pounds (these calls are via the Cart API: https://shopify.dev/docs/api/ajax/reference/cart#post-locale-cart-update-js).

 

I don't love this approach for two reasons. One, it causes a delay between clicking the checkout button and navigating to the checkout page, since it must await these calls. Two, it adds a visible line item to checkout page.

 

My question is whether there is an approach that can alleviate one or both of these issues. A solution involving adjusting the weight of the first line item in the cart instead of adding a line item would be acceptable. Here are the things I have tried or considered:

 

- Cart Transforms API: Doesn't appear to be able to add a line item or adjust weight.

- Webhooks: Besides preferring not to add this complexity, webhooks are async/fire and forget, and so while I could adjust the checkout object upon `checkouts/create`, I can't "call back" to the frontend to tell it to refresh when completed.

- Shipping Discount Function: I don't think this can work in any reasonable way for this use case.

- checkout.liquid - My store does not have a checkout.liquid. My understanding is this is being deprecated and requires contacting Shopify to enable, but my past experience going down this path with a similar request (Script Editor) took weeks and the request was ultimately denied after a promise it would be enabled - very frustrating. Anyway, idea here is I could possibly hide the shipping weight line item.

- Checkout UI Extensions - It appears I can render before and after the line item, but I don't seem to be able to control the line item fully in such a way that I could render nothing at all.

 

Any suggestions would be greatly appreciated. FWIW, this is a Shopify Plus store.

Replies 0 (0)