Shipping Costs Based on Distance for Magento 2

Based on 2 reviews
Calculate shipping costs from the driving distance between your store and the delivery address, using the Google Maps API.
Browse Changelog
Links
15 day Money Back Guarantee One Time Payment
Magento Cloud Support GraphQL Support Hyvä Support Adobe Approved Private Composer Repo
Changelog v1.9.0 | Documentation
Trusted by hundreds of Magento merchants. Maintained for over 6 years and updated frequently, last: v1.9.0 on January 8, 2026.

Calculate Shipping Costs Based on Distance With the Google Maps API

A Shipping Rate That Follows the Route to Your Customer

Shipping Costs Based on Distance for Magento 2 adds a shipping method that prices delivery by the driving distance between your store address and the delivery address. Google Maps calculates the route by road, not a straight line, from the city, postcode and country the customer enters. Street and house number are not part of the request.

You set the price per distance zone in the admin: a fixed amount, a price per kilometre or mile, or both. In the checkout the customer sees the method with the distance in brackets behind the title, for example "(12.5)".

That suits stores that deliver with their own van or a local courier, where every extra kilometre costs time and fuel.

Magento 2 checkout with a shipping method priced by the driving distance to the delivery address

Driving Distance by Road

Google Maps calculates the route from your store address to the city, postcode and country of the customer.

Price Zones

A fixed amount, a price per kilometre or mile, or both, in as many distance zones as you need.

Limit Rules

A maximum distance, a minimum order amount, specific countries, a minimum and maximum price and free shipping above an order amount.

Selected Products Only

A yes/no product attribute decides which products can be delivered with the distance method.

Estimate on the Product Page

The customer enters a country, city and postcode and sees the distance and the cost before the checkout.

Cached for 24 Hours

A repeat calculation for the same city, postcode and country comes from the cache and does not cost a new Google request.

Connect Google Maps and Set Your Starting Point

All settings are in the Magento configuration under "Magmodules" > "Shipping Costs Based on Distance". In "General" you choose the "Google Maps API Version": "Routes API (Recommended)" or "Distance Matrix API (Legacy)". The default is the Distance Matrix API, the older of the two. Enable the API you select in your Google Cloud Console.

Paste the key in "API Key" and enter the "Store Address", the store or pickup point every distance is measured from. The button "Check Credentials" tests the connection from the configuration page and answers "Credentials correct!" when it works.

The method appears in the checkout once two switches are on: "Enabled" in "General" and "Enabled" under "Name and Position" in "Shipping Method". Both are off after installation.

A Google Maps API Key Is Required

The extension needs a Google Maps API key from the Google Cloud Platform. The key is stored encrypted in the Magento configuration. Google sets its own request limits and prices, so check the Google Maps Platform pricing for your expected volume.

Magento 2 admin with the Google Maps API version, the API key, the store address and a successful credentials check
Magento 2 admin with the Shipping Price table and a drawing of a 20 km route that adds up to a shipping price of 15.00

Fixed Fees and Per-Kilometre Rates in One Table

The group "Shipping Method" holds the calculation under "Calculation and Pricing". You decide how distance is measured, how it is rounded and what each zone costs:

  • "Metric": calculate in "Kilometers" or "Miles".
  • "Round Distance" and "Round Total Price": "2 decimal", "1 decimal", "0 decimal - normal", "0 decimal - ceil / up" or "0 decimal - floor / down". Rounding up or down always goes to a whole number.
  • "Shipping Price": a table with "From", "To", "Price" and "Type". Add as many rows as you need with "Add Zone".
  • Type "Fixed" charges a set amount for the zone. Type "Per/metric" multiplies the price by the full distance.

A Base Fee Plus a Rate per Kilometre

All rows that cover the distance are added up. An example: 0 to 10 km costs a fixed 5.00. From 10.01 to 50 km you charge a fixed 5.00 plus 0.50 per km. A delivery of 20 km then costs 5.00 plus 20 times 0.50, so 15.00. "From" and "To" both count, so start the next zone at 10.01 when rows should not overlap.

A distance that falls in no zone is priced at 0.00. Let the zones connect, save a "Round Distance" that matches the decimals in your table and use "Minimal Price" or "Maximum Distance" from the limit rules as a safety net.

Free Shipping and a Minimum and Maximum Price

The group "Limit Rules" starts with two rules for the price itself:

  • Free shipping: turn on "Enable Free Shipping" and set a "Minimal Order Amount". Shipping is free when the subtotal including tax is above that amount.
  • Minimum and maximum shipping price: with "Use Minimum and Maximum" the calculated price stays between "Minimal Price" and "Maximum Price".

In the example an order above 250.00 ships for free, and every other delivery costs between 5.00 and 25.00, whatever the distance. Free shipping goes first: the minimum price is not applied to an order that qualifies.

Magento 2 admin with the limit rules for free shipping and a minimum and maximum shipping price
Magento 2 admin with the maximum distance settings next to a drawing of two distance zones around the store

Keep Delivery Within Your Area, Countries and Order Size

Three more rules in "Limit Rules" decide where and when the method is offered:

  • Limit by distance: turn on "Enable Maximum Distance" and set a "Maximum Distance". Under "Above Maximum Distance" you choose "Show Message" or "Hide Method".
  • Limit by order amount: turn on "Enable Minimum Order Amount" and set a "Minimum Order Amount", checked against the subtotal including tax. Under "Below the Minimum Order Amount" you choose "Show Message" or "Hide Method".
  • Limit by country: with "Ship to Applicable Countries" you offer the method in all allowed countries or only in the countries you select under "Ship to Specific Countries".

The messages for distance and order amount each have their own "Message" field, so you can tell the customer in your own words why delivery is not available.

Offer Distance Shipping Only for Selected Products

The extension adds a yes/no product attribute, "Eligible for Distance Shipping", to the group "Product Details" of your attribute sets. You can filter on it in the product grid. Turn on "Enabled" in the group "Conditions", and "Show Distance Shipping only for eligible products" limits the method to those products. Think of furniture that goes out with your own van while small items ship as a parcel.

Mixed Carts and Other Carriers

With "Allow Distance Shipping for mixed carts" set to Yes, one eligible product in the cart is enough. Set to No, every product in the cart has to be eligible.

"Hide other shipping methods when Distance Shipping is available" removes the other carriers for carts that meet the product conditions in a country you ship to. That check uses the country and the product conditions, not the distance, so the other carriers are also hidden for an address beyond your maximum distance. With "Show Distance Shipping only for eligible products" set to No, it applies to every cart in those countries.

Magento 2 admin with the Conditions settings and the product attribute Eligible for Distance Shipping set to Yes
Magento 2 product page with the Estimate shipping block showing a distance of 20 km and a cost of 15.00

Show Delivery Costs Before Checkout

With "Add Shipping Estimation to Product Page" set to Yes, the product page gets an "Estimate shipping" block. The customer selects a country, enters a city and postcode and clicks "Calculate". The block returns the method name, the distance with its unit, for example "(20km)", and the cost behind the label "Excl tax:". The country list follows your country restriction, and if the distance cannot be calculated the customer is asked to verify the data.

When "Conditions" is enabled and "Show Distance Shipping only for eligible products" is set to Yes, the block only appears on eligible products.

In the checkout the shipping method shows the distance in brackets behind its title, so the customer sees what the price is based on. "Title", "Method Name" and "Sort Order" are yours to set.

An Estimate, Not the Final Price

The estimate uses your price table, the rounding of the total price and the minimum and maximum price. Free shipping, the maximum distance and the minimum order amount are only applied to the actual order in the checkout.

Logging and a Self-Test for Troubleshooting

Errors, such as a failed Google API request, are always written to the error log. Turn on "Debug Mode" in "Debug & Logging" to also log the responses from the Google API and from the cache. You then see which distance a calculation used and whether it came from Google or from the cache. The last log records can be opened from the same configuration page.

The button "Run Self-test" and the CLI command bin/magento distancebasedshipping:selftest run the checks of the extension and report a result per check. That gives a developer or agency a first answer before opening a support ticket.

Magento 2 admin with Debug Mode enabled and the logged responses from the Google API and from the cache

Shipping Costs Based on Distance for Magento 2: Technical Details for Developers and Store Owners

The Advantages for Developers

You choose between the Routes API and the Distance Matrix API, and the API key is stored encrypted in the Magento configuration. A successful distance lookup stays in the Magento cache for 24 hours, and failed lookups are not cached. Debug Mode logs the responses from Google and from the cache, and the self-test runs as a button in the admin and as the CLI command bin/magento distancebasedshipping:selftest. Most settings can be set per website and store view. The switch of the shipping method, "Sort Order" and the country settings go down to website level, and "Debug & Logging" is set in the default scope. Version 1.9.0 runs on PHP 7.4 or higher.

Good to Know for Store Owners

You set the price per distance zone and keep the method within the area, the countries and the order size you want to serve. A second store view can use its own address, title and price table. Google sets its own request limits and prices for the Maps API, so check the Google Maps Platform pricing for your expected volume.

Start Charging Shipping by Distance

Shipping Costs Based on Distance needs a Google Maps API key and is set up in the Magento admin. Magmodules is a plugin developer from the Netherlands and supports every merchant who runs its extensions.

Get the extension Read the documentation

What our customers say

Shipping Costs Based on Distance Reviews

Excellent App, support and guidance

The service provided by Magmodules has been fantastic, we have complex requirements that they supported us through with patience and diligence. Highly recommended.

Richard - The French Cake Company

Using this extension?

Share your experience and help other merchants decide.

Loading...

Knowledgebase

All familiar Help articles

A list of the most frequently asked questions from the Shipping Costs Based on Distance extension for Magento 2. We've tried our best to help you with the installation, configuration and troubleshooting. If you do not find the answer you were looking for, you can always send us a message through this form.

Installation articles

arrow-circle-right Installation using Composer (recommended) arrow-circle-right Install through FTP and SSH

Configuration

arrow-circle-right Quick Start Guide arrow-circle-right Configuration

Changelog 1.9.0 is released on 8 January 2026

Our plugins are regularly updated to ensure compatibility with the latest Magento release.

Version 1.9.0 8 January 2026

Features

  • Added support for the new Routes API for distance-based shipping calculations.
  • Added an option to continue using the legacy Distance Matrix API (default).

Minimum requirements

  • Magento 2.3.x & PHP 7.4

Note

  • For Existing Installations: Your installation will continue using Distance Matrix API by default. You can migrate to Routes API at your convenience by enabling it in Google Cloud Console and switching the configuration.
Version 1.8.2 4 November 2025

Bugfixes

  • Fixed issue with conditions filter where the method was not showing in some cases.

Minimum requirements

  • Magento 2.3.x and up
  • PHP 7.4 and up

Quality

Approved, Compatible and Tested

Adobe Commerce Marketplace Approved

This extension is listed on the official Adobe Commerce Marketplace and has passed their review process for code quality, performance and security.

Adobe Marketplace approval means the extension follows Magento coding standards and integrates properly with the platform. Updates go through the same review process.

Hyvä Compatible Plugin

This extension includes full support for Hyva Themes. All frontend components, widgets and templates work natively with Hyva's Alpine.js and Tailwind CSS stack.

The extension works out of the box on Hyva and is tested with every new Hyva release to ensure continued compatibility.

GraphQL Made Ready

This extension exposes its data and configuration through Magento's GraphQL API. You can query and mutate data directly from headless frontends or custom applications.

The GraphQL schema follows Magento's conventions and covers all key functionality of the extension. This makes it ready for PWA Studio, Vue Storefront or any other headless setup.

Magento Cloud Support

This extension is fully compatible with Adobe Commerce Cloud (Magento Cloud). It works with the read-only filesystem, the build and deploy pipeline and cloud-specific caching layers.

No additional configuration or workarounds are needed for cloud environments. The extension handles static content deployment and config management the same way as on-premise installations.

Private Composer Repo

After purchase you get access to a private Composer repository with personal credentials. Install and update the extension with a single composer command, just like any other dependency.

Your Composer credentials are available in your account dashboard. Updates are published to the repository as soon as a new version is released, so you always have access to the latest version.

star star star star star
star star star star star
Gaaf - digital agency
We have tried the integration with SnelStart through several different providers, and this is the only solution that simply works. We needed support on two occasions, and it was provided quickly and professionally. We do recommend this company!
Google 12 May 2026
star star star star star
star star star star star
Andrew Velikiy
Great vendor with handy modules and quick support!
Google 13 Apr 2026
star star star star star
star star star star star
Alexandru-Manuel Carabus
Magmodules sets the bar for Magento module quality and support—we check their catalog first for client feature requests, and they’re our first choice for licenses.
Google 11 Nov 2025
star star star star star
star star star star star
Matt Austin
Possibly the fastest support response times of any Magento Extension vendor. Great extensions too!
Google 09 Sep 2025
star star star star star
star star star star star
Jan Privé
Dankzij de heldere uitleg en snelle reactie van Magmodules kon mijn vraag, en dus mijn Magento-probleem, binnen enkele uren worden beantwoord. Doeltreffend, zonder moeilijke termen, gewoon zo als het zou moeten zijn.... Bedankt!
Google 05 Sep 2025
star star star star star
star star star star star
Denis Metzler
To evaluate a provider, it is not enough to consider only the product offered, but also its after-sales service, such as support and troubleshooting. Magmodules has been extremely satisfactory at all levels on multiple occasions and sets the bar at the top when comparing the competition.
Google 02 Sep 2025
star star star star star
star star star star star
Bleijenberg winkelinrichting en materialen
Goed bereikbaar, reageren snel en denken oplossingsgericht. Een aanrader.
Google 30 Jul 2025
star star star star star
star star star star star
Patrick Verduijn
Magmodules biedt plugins aan die van hoge kwaliteit zijn tegen een goede prijs, waar dit bedrijf in uitblinkt is de bereidheid om de zeldzame feedback & problemen met de plugins te willen onderzoeken, mee te willen denken in het debuggen van problemen en goede oplossingen toe te passen. In mijn decennium ervaring met Magento & 3th parties is Magmodules absoluut een uniqum binnen de markt.
Google 25 Jul 2025
star star star star star
star star star star star
Erik de Groot
Magemodules heeft hele sterke Magento extensies en een proactieve support. Al jaren heel erg tevreden over jullie service en producten!
Google 18 Jul 2025
star star star star star
star star star star star
René Zeuner
We are using the Mollie Magento extension from Magmodules. It works excellently without flaws. Very fast, competent and friendly support. Thanks!
Google 30 Jun 2025