rakcode
rakcode

Reputation: 2296

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 page. I've created a small Embedded App to initiate the maps. The app uses NodeJS, Koa, NextJS, and React and I'm planning to create an Endpoint with 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.

Upvotes: 0

Views: 1804

Answers (1)

David Lazar
David Lazar

Reputation: 11427

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.

Upvotes: 2

Related Questions