The WooCommerce Distance Rate Shipping extension lets you set up rules and charge shipping rates based on the distance from your default shipping location (origin) to your customer’s shipping address (destination).
Rules can be set up to charge shipping based on the distance and total travel time, or the number of items in the cart, weight of the items, or the total value of the cart.
This extension currently uses the Routes API, which is the next generation version (v2) of the legacy Distance Matrix APIs that was used in older versions (pre 1.7.0).
A Google Cloud account with a payment method added is required, as API access is a paid service and charges will be incurred from Google after the free use cap.
Installation
↑ Back to topThe simplest way to start using a product from WooCommerce.com is to use the “Add to store” functionality on the order confirmation page or the My subscriptions section in your account.
- Navigate to My subscriptions.
- Find the Add to store button next to the product you’re planning to install.
- Follow the instructions on the screen, and the product will be automatically added to your store.
Alternative options and more information at:
Managing WooCommerce.com subscriptions.
Setup and Configuration
↑ Back to topNote: The legacy Distance Matrix API is being deprecated by Google and is no longer available for new users, in favor of the Routes API.
If you are setting up this plugin for the first time, you must use the Routes API.
If you are currently using the legacy Distance Matrix API, it is strongly recommended that you switch to the Routes API to prevent any service disruptions and ensure that shipping rates can continue to be calculated during checkout.
To use the Routes API, you must be using Distance Rate Shipping version 1.7.0 or higher and the “API Type” on the WooCommerce > Settings > Shipping > Distance Rate page should have the “Routes API” option selected. To obtain the API Key, follow the instructions below.
Obtain a Google API Key
↑ Back to top- Go to: https://console.developers.google.com and sign in with an existing Google account or create a new account.
- Click the Create Project button and give it a name (ex: “Distance Rate Shipping”).
- Next, click the Library link in the left sidebar menu.
- Search for the “Routes API” and click it in the search results.
- Click on the Enable button.
- If you have not added a payment method to your Google account already, go through the steps to create a Payments profile and add a payment method when prompted.
- Once the “Routes API” has been enabled, search for the “Maps Embed API“, click on it in the search results, and then click the Enable button.
- Next, click the Keys & Credentials link in the left sidebar menu.
- If a Maps Platform API Key has already been created, it will show in the list of API Keys on that page. Click on the name to view the Key restrictions and make sure that the Application restrictions is set to “None” and API restrictions is set to “Don’t restrict key“, then click Save.
- If a Maps Platform API Key has not been created yet, click the Create credentials dropdown at the top of the page and choose “API key“. For the Key restrictions, make sure that the Application restrictions is set to “None” and API restrictions is set to “Don’t restrict key“, then click Save.
- To view the API key, click “Show key”. Copy the API key and paste it into the API Key field on the WooCommerce > Settings > Shipping > Distance rate page and ensure that the API Type is set to “Routes API“. Once you save the settings, you should see a banner under the API Key field that says “API connected.“
API & Debug
Go to: WooCommerce > Settings > Shipping > Distance Rate.
- API Type — This dropdown allows you to choose between the “Distance Matrix API (legacy)” and the “Routes API”. Google is deprecating the Distance Matrix API, so the Routes API should be used.
- API Key — Your Google API Key can be obtained by following the instructions in the Obtaining Google API Key section above.
- Debug Mode — Enable this to view the API calls on the Cart/Checkout page to debug distance issues.
API Key Restrictions (Security and Compatibility Guide)
↑ Back to topThe WooCommerce Distance Rate Shipping plugin sends requests to the Google Maps API from your site’s server — not from the visitor’s browser.
Because of this server-side behavior:
- Domain-based (HTTP referrer) restrictions will not work and may cause errors like “Requests from referrer are blocked.”
- Unrestricted API keys will work reliably, but they pose a higher security risk if exposed.
- IP-based restrictions can work — but only if your server has a static IP address.
Recommended Setup
To secure your API key while ensuring compatibility:
- Apply API restrictions to limit it to the required services:
- Google Maps Distance Matrix API
- Google Maps Routes API (if used)
- If your hosting provider confirms your server has a static outbound IP, you may use IP-based application restrictions:
- Example for IPv4: xxx.xxx.xx.xxx/32
- Example for IPv6: xxxx:xxxx:x::xxx/128
CIDR Notation Tip:
- /32 for a single IPv4 address
- /128 for a single IPv6 address
How to Find Your Server’s IP Address
You can check your server’s IP by using the host command on your domain:
host yourdomain.com
Example output:
yourdomain.com has address xxx.xxx.xx.xxx
yourdomain.com has IPv6 address xxxx:xxxx:x::xxx
Still unsure? Contact your host and ask:
“What IP addresses are used for outbound API requests from my site/server?”
Budget Alert Tip
To help prevent unexpected charges in case your API key is compromised:
- Set API usage budget alerts in your Google Cloud Console.
- Example: Alert at €10
Enable Billing on Google Cloud Platform
↑ Back to topAs this extension makes use of Google Cloud service, you need to enable billing for your Google Cloud Project on the Google Cloud Platform:
- Navigate to the project page on your Google Cloud Platform
- Select the project you created during your initial setup for this extension
- Click Create Billing Account and complete the rest of the process

Store setup
↑ Back to topNote:
This shipping method has to be added to a Shipping zone. If you haven’t configured your Shipping zones yet, please check our Setting up Shipping Zones guide before proceeding.
- Go to WooCommerce > Settings > Shipping > Shipping zones.
2. Click the Edit button on the shipping zone where you want to offer this method.

3. Inside the shipping zone, click the Add shipping method button.

4. Then, select the shipping method and click the Continue button.

- Select the Edit button on the right side of the Shipping methods table to configure the settings:
- Method Title — Name the shipping method. This is visible to customers.
- Tax Status — Whether the rates include tax or not.
- Transportation Mode — Method of transportation that is being used for delivering your products.
- Avoid — Things to avoid when working out the distance; None, Tolls, Highways, or Ferries.
- Distance Unit — Whether to use the Metric or Imperial system for working out distances.
- Show Distance — Whether to show the actual distance on the cart/checkout pages when presenting the customer with their shipping rate.
- Show Duration — Whether to show an approximation of how long the delivery would take.
- Shipping Address — The address from where you are shipping from, this can be your store location or, if you ship from a different location to your store, enter the address of that location here.
You can also use a Google Plus Code for the first line of the address.
Distance Rate Rules
Add Distance Rate Rules to define different settings for shipping.

Multiple rules can be set up with different options:
- Condition is to specify what rules are based on, be it distance, total travel time, cart item count, weight, or cart total value.
- Min and Max to specify a range the type will fall in (travel time based in minutes). Leave the fields blank if there is no limit.
- Base Cost for rule, excluding tax. Other calculations will be added on top of this cost.
- Cost Per Distance / Minute is the value to charge based on the total travel time or distance to the customer address, excluding tax.
- Unit that is used for calculation, either distance or travel time.
- Multiply by Qty, the cost will be multiplied by quantity.
- Handling Fee allows you to enter a fixed amount or percentage that is added to the shipping cost (such as 2.50 or 5%).
- Break will stop looking for any other rates below this rule (top-down), if the condition is met. Rates calculated up to the Break point will be offered.
- Abort will disable this shipping method, if the condition is met. No rates will be offered.
If you selected Total Travel Time, the travel time returned is an average time for the route.
Note: ranges cannot overlap.
A working example is:
- Range 1: 1-9.9 miles
- Range 2: 10-24.9 miles
A nonworking example is:
- Range 1: 1–10 miles
- Range 2: 10–25 miles
Advanced Mode
The Advanced Mode feature allows you to create complex rule conditions by combining multiple criteria using AND/OR logic. This powerful enhancement overcomes the limitation of evaluating conditions individually, allowing you to create sophisticated shipping rules based on multiple factors.
To create Advanced Rules:
- Head to your to your Distance Rate shipping method in the appropriate shipping zone.
- Select “Enable Advanced Mode”
- Create your needed advanced rules

Multiple rule groups can be set up with the following options:
- Condition Type (AND/OR) – Choose how multiple conditions within a group should be evaluated:
• AND – All conditions in the group must be true for the shipping rate to apply
• OR – Any condition in the group can be true for the shipping rate to apply
Example use case: Free shipping for nearby customers with large orders
Create a rule group with the following conditions (AND type):
- Condition 1: Distance – Min: 0, Max: 10 (miles)
- Condition 2: Cart total value – Min: 100, Max: [blank]
- Base Cost: 0
This creates a free shipping option for customers within 10 miles who spend $100 or more.
Example use case: Varied shipping rates based on distance OR weight
Create a rule group with the following conditions (OR type):
- Condition 1: Distance – Min: 20, Max: 50 (miles)
- Condition 2: Weight – Min: 10, Max: 20 (lbs)
- Base Cost: 15
This creates a $15 shipping option for customers either between 20-50 miles away OR with orders weighing 10-20 lbs.
Select Save changes when you are happy with your rules.
Use Cases
↑ Back to topOnly offer Distance Rate Shipping for shipments below a certain distance
↑ Back to topLet’s say you offer a delivery service within a 50-mile range of your warehouse and want to have the Distance Rate API calculate a delivery cost based on distance traveled. You can set a Distance condition rule with a Max value of 50.

Any distance calculated at Checkout beyond 50 will not match the rule and an error message will be shown:

No cost for the first range, only charge for distances beyond that
↑ Back to topIf you want to allow free shipping for closer deliveries (like the first 20 miles, for example) but charge for shipments further away than that, you can achieve this by adding a “0” cost rule for the free shipping distance (Min 0, Max 20). Then add another rule for distances beyond that (20.1 miles as the Min, Max can be left blank or assigned a range). In this second rule, set the “Cost Per Distance / Minute” amount that you want to charge (for $5 per mile, just enter 5 in that field), but add a negative amount in the “Fixed Cost” field that equals the number of miles in the free distance range multiplied by the cost per mile (20 × 5 = 100, so enter -100 as the fixed cost).

Troubleshooting
↑ Back to topError showing on Distance Rate Shipping settings page: ‘Google Maps Platform rejected your request. This API project is not authorized to use this API’.
↑ Back to topThis can happen when using the “Distance Matrix API (legacy)” API type and the Google Maps Embed API is not enabled for the project you created. Open the Google Developer Console and make sure that both Google Distance Matrix API and Google Maps Embed API are added to the project. Select the Enable APIs & Services button and search for each of the above APIs to enable them.

Conditions can only be evaluated individually, not in combination with each other workaround
↑ Back to topThe functionality can be modified with the custom code snippet below. This uses an example of “Override rule cost for distance shipping when destination within 5 miles of shop AND order total over $100”
add_filter( 'woocommerce_distance_rate_shipping_rule_cost_distance_shipping', function( $rule_cost, $rule, $distance, $package ) {
$order_total = $package['contents_cost'];
if ( $order_total > 100 && $distance <= 5 ) {
$rule_cost = 0;
}
return $rule_cost;
}, 10, 4 );
Scope of support:
We are unable to provide support for customizations under our Support Policy. If you need to customize a snippet or extend its functionality, we recommend working with a Woo Agency Partner or a WooCommerce developer on Codeable.
Questions and Support
↑ Back to topSomething missing from this documentation? Do you still have questions and need assistance?
- Have a question about a specific extension or theme you’d like to purchase? Use our Contact us page to get answers.
- Have you already purchased this product and need some assistance? Get in touch with a Happiness Engineer via the WooCommerce.com Support page and select this product name in the “Product” dropdown.