A taxi fare calculator for WordPress is a function inside a taxi booking plugin for WordPress that computes the price of a ride based on distance, duration, vehicle type, time of day, and applicable surcharges. It runs server-side in PHP, queries the Google Maps Distance Matrix API for real road distance and duration between pickup and dropoff, applies the pricing rules configured by the business owner, and returns a final fare in the site’s currency. It’s the single most important component of a taxi booking system. The booking form, calendar, and driver panel are all interchangeable, but the fare engine is what separates a real taxi plugin from a glorified contact form.
This page covers the four pricing models a serious calculator must support (per-kilometre, per-hour, tiered distance, tiered hourly), how geofence-based fixed fares work, what surcharges look like in real life, why the calculation must run server-side, and how multi-vehicle pricing should be structured.
What is a taxi fare calculator for WordPress?
A taxi fare calculator for WordPress is a function inside a taxi booking plugin that computes the price of a ride based on distance, duration, vehicle type, time of day, and applicable surcharges. The calculator runs server-side using PHP, queries the Google Maps Distance Matrix API for distance and duration between pickup and dropoff, applies the pricing rules configured by the business owner, and returns a final fare in the site’s currency.
The calculator is the single most important component of a taxi booking system. The booking form, the calendar, the driver panel. All are interchangeable. The fare engine is what separates a real taxi plugin from a contact form with extra fields. A business that bills wrong loses money or loses customers. There’s no third option.
A complete fare calculator handles four core pricing models. Per-kilometre, per-hour, tiered distance, and tiered hourly, plus geofence-based fixed fares and configurable surcharges. Each vehicle in the catalog uses its own pricing strategy, and the calculator picks the right one automatically at booking time.
How does a taxi fare calculator work in WordPress?
The calculator runs through five steps from address entry to displayed price.
Customer enters pickup and dropoff
The taxi booking form for WordPress uses Google Places Autocomplete on the address fields. As the customer types, the field suggests real addresses. When both fields have a value, the calculator triggers.
Plugin queries Distance Matrix API
The plugin sends pickup and dropoff coordinates to the Google Maps Distance Matrix API. Google returns distance in metres and duration in seconds, accounting for current traffic if requested.
Plugin checks for geofence match
Before applying distance-based pricing, the calculator checks whether the pickup or dropoff falls inside a configured polygon geofence. If a zone-to-zone fixed fare matches, that price wins and the calculation stops there.
Pricing engine runs for each vehicle
For each active vehicle, the calculator applies the vehicle’s pricing strategy (per-km, per-hour, tiered distance, tiered hourly), adds base fare, enforces minimum fare, and stores the subtotal.
Surcharges and total returned
The calculator applies any matching surcharges (night, weekend, holiday), adds them to the subtotal, and returns the final fare. The customer sees a price grid with one row per vehicle.
The whole calculation takes under 400 milliseconds in normal conditions. The Distance Matrix API call is the slowest part, typically 150 to 250 milliseconds. Plugin code accounts for the rest.
What pricing models should a WordPress taxi fare calculator support?
A serious taxi fare calculator supports at least four pricing models, with the ability to assign a different model to each vehicle.
Per-kilometre
Base fare + (distance × rate per km) + (duration × rate per minute, optional). The classic taxi pricing model. Used by most city taxi services.
Per-hour
Base fare + (duration in hours × hourly rate). Used for chauffeur hire, city tours, and rides where the time matters more than the distance.
Tiered distance
Different rates for different distance bands. €3/km for the first 5 km, €2/km for the next 15 km, €1.50/km beyond. Standard for serious operators.
Tiered hourly
Fixed packages by hours. 4 hours = €120, 8 hours = €200, full day = €350. They selects how many hours they want. Common for wedding cars and corporate hire.
How is per-kilometre fare calculated?
The formula for per-kilometre pricing is straightforward:
Fare = max( base_fare + (distance_km × per_km_rate) + (duration_min × per_minute_rate), minimum_fare )
The per_minute_rate is optional and represents time-in-traffic charges. Many operators set it to zero. The minimum_fare prevents very short rides from coming in under cost, a 0.8 km hop shouldn’t bill at €1.60 if the operator’s minimum is €8.
How does tiered distance pricing work?
Tiered distance pricing applies different per-km rates to different distance bands within the same ride. A typical configuration:
- 0 to 5 km: €4 per km
- 5 to 20 km: €2.50 per km
- 20 to 50 km: €1.80 per km
- 50 km and above: €1.50 per km
For a 30 km ride, the calculator bills: (5 × €4) + (15 × €2.50) + (10 × €1.80) = €20 + €37.50 + €18 = €75.50, plus base fare. This is how real-world taxi meters work and how serious airport-to-suburb pricing should be structured.
How does tiered hourly pricing work?
Tiered hourly pricing presents the customer with packages. They selects how many hours they want from a dropdown, and the calculator returns the fixed package price for that duration. Distance is irrelevant within the package, the driver stays with the rider for the agreed hours.
This pricing model works for wedding transport, city tours, corporate executive hire, and any service where the customer wants the car at their disposal for a known block of time.
What is geofence pricing in a taxi fare calculator?
Geofence pricing. Also called zone pricing or flat-rate pricing, allows the business to define geographic zones on a real map and assign fixed fares between them. When the customer’s pickup or dropoff falls inside a defined zone, the geofence fare overrides any distance-based calculation.
This is how every professional airport transfer service prices its rides. A trip from “city centre” to “Heathrow Airport” has one price, regardless of which route the driver takes. Distance-based pricing breaks down because the M4 motorway is 3 km longer than the A4 route but takes 12 minutes less, and the customer should not pay more for the driver choosing the better road.
How geofences are configured
In a well-designed plugin, the admin draws polygons directly on a Google Map in the WordPress dashboard. Each polygon has a name (Heathrow Terminal 5, City Centre, Hotel District, Stadium Zone, etc.). Then the admin creates fare entries that specify:
- Origin zone (or “any location outside zones”)
- Destination zone (or “any location outside zones”)
- Vehicle type the rule applies to
- Fixed fare in the site’s currency
- Whether the rule is directional or bidirectional
When a customer requests a ride, the plugin runs a point-in-polygon check on both pickup and dropoff coordinates. If a matching zone-to-zone rule exists for the selected vehicle, the fixed fare is returned. If not, the calculator falls back to whichever distance-based or hourly model the vehicle is configured to use.
What surcharges should a taxi fare calculator support?
Surcharges are additional charges applied on top of the base fare under specific conditions. A complete fare calculator supports three types of surcharges with two application modes.
| Surcharge type | Trigger | Example |
|---|---|---|
| Time-based | Pickup time falls inside a configured window | 22:00–06:00 night premium of 20% |
| Date-based | Pickup date matches a specific date | Christmas Day surcharge of €15 flat |
| Day-of-week | Pickup falls on a configured weekday | Saturday and Sunday surcharge of 10% |
Each surcharge should be configurable as either a flat amount (€5 added to the fare) or a percentage (10% added to the subtotal). Each surcharge should also support per-vehicle opt-out, premium vehicles might not apply a night surcharge because their base rate already accounts for it, while economy vehicles do.
Surcharges stack in a defined order: time-based first, then date-based, then day-of-week. Whether the percentage is calculated on the pre-surcharge subtotal or the running total matters and should be documented in the plugin.
Why does the calculator need the Google Maps Distance Matrix API?
The Distance Matrix API is Google’s service for calculating distance and travel time between two points along the actual road network. Not the straight-line distance, which is useless for taxi pricing.
A 5 km straight-line distance between two riverside addresses might require 18 km of actual driving if the nearest bridge is several kilometres downstream. Charging for straight-line distance would result in the business being underpaid on every cross-river ride. The Distance Matrix API returns the real route distance, the kilometres the driver actually drives.
What the API needs
The Distance Matrix API requires four things to be enabled and configured in a Google Cloud project:
- Maps JavaScript API for the map display
- Places API for address autocomplete
- Directions API for drawing the route on the map
- Distance Matrix API for the distance and duration values used in fare calculation
All four are billed against the same Google Cloud project. Google provides a $200 monthly free credit, which covers approximately 25,000 map loads, 11,000 distance matrix requests, and 28,000 autocomplete sessions. Most small to medium operators stay well inside the free tier.
Why must the fare calculation run server-side?
The fare must be calculated on the WordPress server in PHP, not in the browser in JavaScript, for one reason: a JavaScript-calculated fare is a fare the customer can manipulate.
Any value sent from the browser to the server can be edited by anyone with developer tools open. A booking system that trusts a price calculated in JavaScript and posted by the form is a booking system that can be charged €1 for a €100 ride. The plugin’s REST endpoint must recalculate the fare server-side at booking submission time, using the same logic that produced the original quote, and reject the booking if the values do not match.
Client-side fare values are display-only. The server must always recalculate. Plugins that store the displayed price in a hidden input and accept it at submission are insecure and will be exploited eventually.
Does the fare calculator support multiple currencies?
The fare calculator uses whichever currency is configured in WooCommerce. The plugin doesn’t maintain its own currency setting, it reads from get_woocommerce_currency() and formats prices through wc_price(). This is the right architecture because the WooCommerce taxi booking plugin layer handles currency, tax, decimal separators, thousand separators, and currency symbol position for every locale.
For multi-currency sites (a UK business that takes USD and EUR for international customers), the standard approach is to use a WooCommerce multi-currency extension. The booking plugin honours whichever currency WooCommerce reports as active, so currency switching works without changes to the plugin itself.
Can each vehicle have different pricing?
Yes, and this is the feature that distinguishes a real taxi plugin from a basic one. A fleet typically operates several vehicle classes with different cost structures:
- Economy sedan: per-kilometre pricing with low base fare
- Premium sedan: per-kilometre pricing with higher rates and a tiered structure
- Executive limousine: tiered hourly pricing, minimum 3-hour booking
- 8-seat minivan: per-kilometre with higher rates than the sedan
- Wedding car: tiered hourly only, with packages for 4, 6, and 8 hours
- Airport shuttle: geofence pricing exclusively, with fixed fares to and from named airports
The calculator should let the admin pick one pricing model per vehicle and configure its rates independently. When a customer fills the booking form, the calculator returns a price for every active vehicle, each calculated using its own model. The rider sees a comparison grid and picks the vehicle that fits their budget. For a plugin comparison including fare engine quality, see our best taxi booking plugin for WordPress roundup.
Are there free or open-source taxi fare calculators?
There are some open-source distance calculators on GitHub that compute great-circle or haversine distance between two coordinates. These aren’t taxi fare calculators, they’re mathematical utilities. They don’t query road networks, don’t account for traffic, don’t handle tiered pricing, do not support geofences, and don’t integrate with WooCommerce.
For a working taxi fare calculator inside WordPress, the realistic options are the free tier of the eCab plugin (basic per-km pricing only) or a premium plugin that includes the full calculator as part of its feature set. Building a taxi fare calculator from scratch requires several weeks of PHP and JavaScript work, plus ongoing maintenance for Google API changes, edge cases, and tax handling, which is why almost no operator builds their own. The calculator is one of seven components in a complete WordPress taxi booking system.
Frequently asked questions
What is a taxi fare calculator for WordPress?
A taxi fare calculator for WordPress is a function inside a taxi booking plugin that computes the price of a ride based on distance, duration, vehicle type, time of day, and applicable surcharges, using the Google Maps Distance Matrix API for real road distance.
How accurate is a WordPress taxi fare calculator?
Distance and duration values come from the Google Maps Distance Matrix API, which uses the same routing data as Google Maps itself. Accuracy is generally within 2 to 5 percent of actual driven distance, which is the same accuracy any taxi business gets from any modern routing engine.
Can the fare calculator handle different rates for different vehicles?
Yes. Each vehicle in the catalog has its own pricing strategy (per-km, per-hour, tiered distance, or tiered hourly) with its own rates. It returns a separate price for each active vehicle at booking time.
Does the fare calculator include tax?
Tax handling is done by WooCommerce, not by the fare calculator. The plugin returns the pre-tax fare; WooCommerce applies the configured tax rate at checkout based on the customer’s billing address.
Can the customer see the fare before they pay?
Yes. The booking form displays the calculated fare in real time as soon as both pickup and dropoff addresses are entered. The customer sees the price before confirming and before being sent to checkout.
How does the calculator handle very short rides?
Each vehicle has a configurable minimum fare. If the calculated distance-based or hourly fare is below the minimum, the minimum fare is used. This prevents 0.5 km rides from billing at unrealistically low prices.
Can geofence fares override distance-based pricing?
Yes. The calculator checks for a matching geofence before applying distance-based logic. If the pickup or dropoff matches a zone with a configured fixed fare, that fare wins and distance pricing isn’t applied.
What happens if the Google Maps API call fails?
A well-built plugin shows a clear error message to the customer and prevents the booking from proceeding without a valid fare. It doesn’t fall back to a guessed price, which would result in mispriced rides.
Can the calculator apply different surcharges for different vehicles?
Yes. Each surcharge rule has a per-vehicle opt-in or opt-out toggle. Premium vehicles can be excluded from night surcharges because their base rate already covers it, while economy vehicles apply the surcharge.
Does the calculator work with WooCommerce coupons?
Yes, indirectly. The fare is added to the WooCommerce cart as the product price, and WooCommerce coupon codes apply at checkout in the normal way. Discount codes work without any extra configuration in the booking plugin.