Calculate Shipping Fee Outside Shopify and update Metafield

sachin16
New Member
7 0 0

Hi,

 

I need to calculate my own shipping fee outside Shopify and want to update the value at the time of checkout. Is it possible to do in Shopify creating a metafield, if yes then at what resource will it be? What webhook event do I need to use to notify my API which will calculate the shipping fee and update the metafield?

 

Thanks

0 Likes
hassain
Shopify Staff (Retired)
Shopify Staff (Retired)
624 103 135

Hi @sachin16 ,

 

In order to accomplish what you are looking for, I see four options:

 

  1. Create custom manual shipping rates that have your fee included. You can utilize the Shipping profiles resource in Shopify so you can have greater control and customization on your shipping rates per product and per location: https://help.shopify.com/en/manual/shipping/setting-up-and-managing-your-shipping/setting-up-shippin... and https://help.shopify.com/en/manual/shipping/setting-up-and-managing-your-shipping/shipping-profiles
  2. Use the Carrier Service API, so that on every checkout Shopify will send a request to your app in order to get the value of the Shipping Rates. Your app can return the value of what the shipping rate would be, plus your additional fee. (https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/carrierservice?api[versio...
  3. Create separate products on your store representing the Shipping Fee, and then use the Ajax Cart API to add these products as line items to the customers cart (https://shopify.dev/docs/themes/ajax-api/reference/cart#post-cart-add-js)
  4. Include your shipping fee into your product prices

In terms of using Metafields, I do not think this would be the best approach. The only resource that would make sense would be the Order resource, but you can only access an Order once the checkout has been completed not before and you can only access this metafield with a backend call to the Admin API. You could maybe add the shipping fee on a product level to the Product resource, and then access this metafield via the Storefront API (https://shopify.dev/tutorials/retrieve-metafields-with-storefront-api), but I do not know how you would then leverage the data in this metafield to update the checkout with a higher price. 

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
sachin16
New Member
7 0 0

Hi Hassain,

 

It seems like Carrier Service API is the option that is feasible in our use case and it can be our own custom API calculating the shipping fee. Can you confirm my understanding that after registering our custom API as callbackURL it will send the data as given in your documentation in the request and expect the response(as per documentation) and in this case no WebHook is required? If this is correct then can you tell in which field the shipping fee will be populated back in Shopify, from the response received from custom API. In a broader sense, how can I use the response received from custom API in Shopify form?

 

Thanks,

Sachin

0 Likes
sachin16
New Member
7 0 0

Any update please?

0 Likes
hassain
Shopify Staff (Retired)
Shopify Staff (Retired)
624 103 135

Hi @sachin16 ,

 

Can you confirm my understanding that after registering our custom API as callbackURL it will send the data as given in your documentation in the request and expect the response(as per documentation)?

Yes your understanding is correct. 

 

If this is correct then can you tell in which field the shipping fee will be populated back in Shopify, from the response received from custom API.

In the response sent back from your Carrier Service app to Shopify, there is no field specifically for shipping fee. But since this response is returned by your app, your app can calculate the original price of the shipping + the shipping fee, and return the sum as the "total_price". Then in your description you can write how much of the total price comes from the original shipping rate and how much comes from your shipping fee. 

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes