How to set WooCommerce distance based shipping calculator

WooCommerce distance based shipping
Author Bartosz Gajewski
Updated:
2022-12-13
Reading time:
6 minutes read

Learn how to set distance based shipping calculator in your WooCommerce store. In this article, I’ll show you how to easily offer shipping rates based on Distance or Total Travel Time calculated by Google Distance Matrix API. As a bonus, you will learn how to set progressively increasing shipping fee with additional cost per distance or travel time.

The cost of shipping for ecommerce can depend on many factors. Key factors include the weight and size of the package, the type of delivery, and the distance the shipment is expected to travel. The last factor seems the most obvious of all. The more distance a package has to travel, the higher the shipping fee should be. In WooCommerce, you can set up separate shipping methods for each shipping zone, so you can adjust your prices according to the distance. However, when you, as a store owner, want this calculation to be more accurate, the shipping zones available in WooCommerce may not be enough.

If you want to read about other ways to calculate shipping costs, browse through our article on how to implement a shipping cost calculator in WooCommerce.

Who can benefit using WooCommerce Distance Rate Shipping?

Features to calculate shipping rates based on distance or total time travelled are certainly not for every store. However, there are a lot of businesses that can benefit from it. It will work great for online stores that have their own delivery service, instead of giving shipments to courier companies such as FedEx or UPS. It’s also a perfect solution for local delivery or any other store that need to charge customers the most accurate rates as possible.

How does the distance or travel time calculator works?

The solution I want to present in this article uses Google Distance Matrix API to measure the distance or delivery duration between store address locations and customer addresses.

The API returns information based on the recommended route between start and end points. You can request distance data for different travel modes, request distance data in different units such kilometers or miles, and estimate travel time in traffic. Read more about Google Distance Matrix API.

Set WooCommerce distance based shipping

Knowing how the distance or travel time calculator works, it’s time to configure it in WooCommerce store. I’ll walk you through it step by step. First, you’ll need a plugin…

Distance Based Shipping Rates for WooCommerce plugin

The solution is to use additional tools to determine the exact cost of shipping based on the distance. In this article, I’ll show you how to do it using Distance Based Shipping Rates for WooCommerce plugin. It’s one of the best distance rate shipping plugins available on the market. We packed it with useful features, and most significantly, it is fully compatible with the Flexible Shipping plugin. You can use it with both free and paid versions to get the best shipping experience for your online store.

Distance Based Shipping Rates for WooCommerce
39.00

View Details or Add to cart
Plugins used by 241,719+ shops
30-day money back guarantee
Last Updated: 2024-11-18
Works with WooCommerce 9.1 - 9.5.x

It allows you to set shipping rates based on the distance calculated using Google Maps Distance Matrix Service API.

Not familiar with Flexible shipping plugin yet? This is the most popular WooCommerce shipping rates calculator plugin on the WooCommerce market. It has more than 140,000 active installations and gets great ratings in the WordPress repository.

Flexible Shipping PRO WooCommerce
99.00

The best Table Rate Shipping for WooCommerce. Period. Create shipping rules based on weight, order totals or item count.

View Details or Add to cart
100,000+ Active Installations
30-day money back guarantee
Last Updated: 2024-12-09
Works with WooCommerce 9.1 - 9.5.x

Configure the Distance Based Shipping Rates settings

To start configuration, go to WooCommerce → Settings → Shipping → Flexible Shipping Distance Based Shipping Rates.

First of all, to use distance and duration conditions in Flexible Shipping methods, you need to enter Google Maps API key. To obtain a Google API key, please refer to this article.

Save changes and if API Connection Status turn to Connected, you are good to go.

Distance Based Shipping Rates plugin settings

Google Distance Matrix API allows you to configure the way that Google will calculate distance or travel time. You can choose Travel mode, used by Google API to do so. It can be driving, cycling or walking depending on the types of deliveries that you offer.

Travel Mode in Distance Based Shipping Rates for WooCommerce plugin

The plugin allows you to set the Distance Unit. You can pick between metric and imperial. Please have in mind, that this configuration will be applied to all the shipping rules that you will add later to configure shipping rates.

Distance Unit in Distance Based Shipping Rates for WooCommerce plugin

If you want to avoid calculating shipping costs based on store location (entered in WooCommerce settings), you can provide custom shipping origin. When you select Custom address from Origin field, you will be able to enter the address for the distance calculations.

Custom origin in Distance Based Shipping Rates for WooCommerce plugin

If all is set, save changes and proceed to adding and configuring the shipping methods.

Add Flexible Shipping method

Go to the WooCommerce shipping tab (WooCommerce → Settings → Shipping). Then, click on the shipping zone which to you want to add the feature. I have the ‘UK’ shipping zone:

Shipping zones

Next, click the Add shipping method button:

Add shipping method

Choose the Flexible Shipping and confirm with Add shipping method again.

Add shipping method: Flexible Shipping

Having the Flexible Shipping method added, it’s time to manage WooCommerce shipping method.

In General Settings section, you can set Method Title and Description. Below you can also change the tax settings for shipping and WooCommerce advanced free shipping

Learn what is table rate with our short guide with examples.

To configure shipping fees based on distance or travel time, go to Shipping Cost Calculation Rules table. You’ll find it at the bottom of the shipping method page.

Shipping Cost Calculation Rules table

It’s what you can use to configure the shipping rates in the Flexible Shipping plugin and all add-ons.

Set WooCommerce shipping cost based on distance

First, I’ll show you how to add shipping fee based on distance. In the Shipping Cost Calculation Rules table, you’ll find the first rule set as Always. Click on it to select the Distance condition.

add shipping rule based on distance

Then, you can add a distance range for that rule.

add distance range to shipping rule

As you can see, the ranges are displayed in metric settings, based on the plugin settings. Now, it’s time to add distance ranges and shipping cost for that rule. Let’s say that my shipping costs £10 if the distance is up to 5 kilometers. To configure it like that, just enter distance minimum distance and maximum. Then, enter the shipping fee for that distance rate. It should look like this:

configure first condition based on distance

This configuration means that if the distance between your store (configured in WooCommerce settings or Custom Origin in the plugin settings) is less than 5 kilometers, the shipping fee will be calculated as £10.

You can add multiple rules to get the most accurate shipping charges in your WooCommerce store. For example, if I know that delivery over 5 kilometers costs £20, I can add a second rule.

configure second condition based on distance

To do so, just use the Add rule button and again use the Distance condition.

As you can see, I also set the maximum distance range as 20 kilometers. This means that when the shipping distance will be more than 20 kilometers, that shipping method won’t be displayed in the cart or checkout page. This way, you can set the maximum distance for which the shipping rate will be calculated.

Set WooCommerce shipping rates based on travel time

Now, let’s set delivery rates based on travel time. It will be calculated by Google Distance Matrix API’s preferred route and depends on the travel mode selected in the settings. It will calculate shipping costs based on customer location and shipping origin.

In the Shipping Cost Calculation Rules table, you’ll find the first rule set as Always. Click on it to select the Delivery duration condition.

add shipping rule based on travel time

Then, you can add a delivery duration range for that rule. As you can see, the ranges are displayed in minutes. Now, it’s time to add delivery duration ranges and shipping rates for that rule. Let’s say that my shipping costs £10 if the delivery duration takes up to 15 minutes. To configure it like that, just enter delivery duration minimum and maximum. Then, enter the shipping fee. It should look like this:

configure first condition based on delivery duration

This configuration means that if the travel time between your store (configured in WooCommerce settings or Custom Origin) will take less than 15 minutes, the shipping cost will be calculated as £10.

You can add multiple rules to get the most accurate shipping charges in your WooCommerce store. For example, if I know that delivery over 15 minutes costs £20, I can add a second rule.

configure second condition based on delivery duration

As you can see, I also set the maximum delivery duration range as 30 minutes. This means that when the predicted travel time will take more than 30 minutes, that shipping method won’t be displayed in the cart or checkout page. This way, you can set the maximum delivery duration for which the shipping rate will be calculated.

In the same way, you can add multiple shipping methods in multiple shipping zones, depending on the needs and capabilities of your online store.

Set progressively increasing distance based shipping

Sometimes, setting multiple distance ranges can be problematic and take a lot of time. If your distance ranges change every one kilometer, adding a dozen rules is not a practical solution. Instead, it is better to configure progressively increasing shipping calculator and set additional charge per each kilometer or minute. In this way, you can also set up a shipping scenario, in which above a certain distance, each additional kilometer increases the shipping rate. It might be a handling fee for long-distance deliveries.

Set additional cost per distance

To enable additional cost, click on the plus button next to the shipping rule.

additional cost button

Thereafter, you will be able to set the additional cost.

shipping rule with additonal cost

In the additional cost field, set the exact fee that will be added to the rule cost. Then set the number of kilometers in which the additional fee will be charged. So, if you want to charge additional £1 for each kilometer, set it like that:

shipping rule with configured additonal cost

With that configuration, the shipping fee be £10 + £1 per each 1 kilometer. So, if the distance is 4 kilometers, it will charge shipping as £14.

Please have in mind, that with that configuration, you won’t have maximum distance configured.

Additional cost per travel time

To enable additional cost, click on the plus button next to the shipping rule.

additional cost button

Thereafter, you will be able to set the additional cost. In the additional cost field, set the exact fee that will be added to the rule cost. Then set the number of minutes in which the additional fee will be charged. So, if you want to charge additional £1 for each travel minute, set it like that:

shipping rule with configured additonal cost per travel time

With that configuration, the shipping fee be £10 + £1 per each 1 minute of predicted delivery duration. So, if the travel time takes 12 minutes, it will charge shipping as £22.

Please have in mind, that with that configuration, you won’t have maximum travel time configured.

Summary

In this article, I showed you how to set WooCommerce distance based shipping calculator. I hope that you will find it useful. If you want to configure more advanced shipping calculator, you can combine Distance Based Shipping Rates for WooCommerce plugin with the Flexible Shipping PRO. With both plugins, you will be able to add multiple shipping rules based on shipping class or cart value.

Comments
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments