🎉 Black Friday Month Deal: Save 20% on Premium Bundles! Create Unlimited Shipping Scenarios with ease. Don’t hesitate—offer ends November 30th 🚀  Learn more →
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.
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.
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.
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…
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.
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.
The best Table Rate Shipping for WooCommerce. Period. Create shipping rules based on weight, order totals or item count.
View Details or Add to cartTo 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.
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.
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.
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.
If all is set, save changes and proceed to adding and configuring the shipping methods.
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:
Next, click the Add shipping method button:
Choose the and confirm with Add again.
Having the added, it’s time to .
In General Settings section, you can set Title and Description. Below you can also change the tax settings for and .
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.
It’s what you can use to configure the shipping rates in the Flexible Shipping plugin and all add-ons.
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.
Then, you can add a distance range for that 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:
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.
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.
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.
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:
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.
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.
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.
To enable additional cost, click on the plus button next to the shipping rule.
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 kilometers in which the additional fee will be charged. So, if you want to charge additional £1 for each kilometer, set it like that:
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.
To enable additional cost, click on the plus button next to the shipping rule.
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:
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.
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