How do I refund a single item and shipping proportional to the item refunded?

New Member
4 0 0

I have an order with 3 different line items.

 

I need to refund 1 of those items (which is heavy and adds to the shipping price). Without this item I can reduce the price of the shipping by X.

 

How can I refund X? How can I automatically calculate how much I have to refund from the shipping?

 

The example here doesn't go too much in depth

https://help.shopify.com/en/api/reference/orders/refund#calculate

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1127 79 162

Hey there, 

 

Shopify doesn't have any concept of how much each line item contributes to a certain shipping rate's price, because there's really no way for us to know for sure. We just take the total weight or total price of an order and surface any applicable shipping rates that have been configured. Because of that, there's no way to automatically do this - you'd just have to specify a shipping refund amount manually. 

0 Likes
Highlighted
New Member
4 0 0

Thanks.

 

Because the shipping options we have are all weight based I figured out the amount by:

 

- getting `newWeight = total_weight - (itemGrams * quantity)`

- find the ShippingZone with `weight_min < newWeight < weight_max`

- refunding `currentShippingPrice - newShippingZonePrice`

 

0 Likes