node.js - Dynamic shipping charges in Shopify
I was experimenting on
Shopify since I started learning
Shopify recently. I' a
MEAN stack developer. One thinking came to my mind that how do we update the shipping charges dynamically?
Here is my plan,
There will be a
Google Maps and the usine will pick the location. I've added few fields to the
cart.liquid by reffering to THIS (https://ui-elements-generator.myshopify.com/pages/cart-attribute) page.
I've created a small
Embedded App to initiate the maps. The app uses
React and I'm planning to create an
Koa where I can calculate the shipping charges based on the Geometric distance from User location to Store location.
The calculation will be something like below.
let latA = /* Store Lat */ let lngA = /* Store Lng */ let latB = /* User Lat */ let lngB = /* User Lng */ /* I'll caculate the distance using Google maps API. Lets say, distance is 10KM */ let shippingCharge = 10 * 50;
I can get this value and set it as
Cart Attribute. But I want to collect the amount from the user, so, Is there any way to send this to checkout page as shipping charge?
I can't use
Shopify shipping methods since my shipping charge will be created dynamically.
Any store can add the Custom Carrier Services to it. You get an endpoint in your own custom App to return shipping costs to customers in checkout. The payload of data from Shopify to work with includes the origin, destination and some details on the items being shipped. It lacks real depth of course, but if you are clever, you can leverage product properties to customize a bit.
So you get to figure out how much to charge between A and B, for the items.
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.