Gatemi Distance Shipping Developer Reference

The free edition applies no filters or actions of its own. Everything under Filters is the full edition's; its settings screen lists them under Filters.

Filters — Full edition

gmdrs_destination

The address sent to Google for a package. Return an empty string to refuse the lookup — the method then offers no rate.

Argument Type
$address string The composed address, or '' when the destination is not specific enough
$destination array The package's destination array
$package array The whole package
// Never look up deliveries to PO boxes.
add_filter( 'gmdrs_destination', function ( $address, $destination ) {
	$line = strtolower( (string) ( $destination['address_1'] ?? '' ) );
	return false !== strpos( $line, 'po box' ) ? '' : $address;
}, 10, 2 );

gmdrs_journey

A looked-up journey, before it is remembered. Applied only to a successful lookup.

Argument Type
$journey GatemiDistanceShippingDistanceJourney Distance in metres and duration in seconds
$origin string The origin address
$destination string The destination address

Return a Journey; anything else is ignored.

gmdrs_request_timeout

Seconds the Routes API request may take. Default 5, minimum 1.

gmdrs_settings

The settings array, merged over the defaults, every time it is read.

Others

Filter What it changes
gmdrs_modules The module list the plugin boots
gmdrs_license_api_url The licence API base, default https://gatemi.com/wp-json/gatemi-license/v1
gmdrs_update_cache_ttl How long an update answer is cached
gmdrs_update_retry_ttl How long to wait after a failed update check
gmdrs_sync_cache_ttl How long a shared licence roster is cached

Actions — Full edition

gmdrs_booted fires once all modules are wired, with the service container.

The shipping method

  • Method id: gmdrs_distance_rate (both editions)
  • Title in the zone list: Distance rate
  • Instance settings: title, tax_status, rows — stored by WooCommerce in woocommerce_gmdrs_distance_rate_<instance id>_settings
  • Rates are added with calc_tax set to per_order.

The method is registered on woocommerce_shipping_methods and its class is loaded on woocommerce_shipping_init.

Settings option: gmdrs_settings

Key Default Edition
api_key '' both
origin '' (WooCommerce store address) both
unit km both
cache_days 30 both
no_rate '' both
mode DRIVE full (free always drives)
log no full

The free edition's save writes only the five keys it shows and keeps the other two as they were.

Remembered journeys

  • Transient name: gmdrs_d_ + md5( origin | destination | mode ), with both addresses lower-cased and whitespace collapsed.
  • Value: metres and seconds (free edition) — the same journey shape the full edition reads.
  • Lifetime: cache_days days.
  • Failed lookups are never stored.
  • Saving gmdrs_settings bumps WooCommerce's shipping transient version, so cached package rates are recalculated.

The request

POST https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix
X-Goog-Api-Key: <your key>
X-Goog-FieldMask: originIndex,destinationIndex,duration,distanceMeters,condition

with one origin and one destination as address waypoints, the travel mode, and metric units. A result whose condition is not ROUTE_EXISTS, or that has no distanceMeters, is a failure.

Logging — Full edition

With Write failed lookups on, failures go to wc_get_logger() at warning level with the source gmdrs-distance-shipping.

Storefront

There is no storefront script, stylesheet or template. The only storefront output is the rate in WooCommerce's shipping list and, when set, the no rate sentence as a WooCommerce notice.

Shopping Cart
Scroll to Top