Signature
$drivers = apply_filters( 'get_available_drivers_for_lat_lon', array(), float $lat, float $lon, int $max_distance );
| Parameter | Type | Description |
|---|---|---|
$available_drivers |
array |
Seed array (pass array()); the handler appends to it. |
$lat / $lon |
float |
The point to search around (typically the rider’s GPS position). |
$max_distance |
int |
Radius in miles, straight-line. The plugin’s own call uses 10. Optional — the handler defaults it to 10. |
Returns a numerically indexed array, sorted nearest first. Each element:
array(
'distance' => 3.2, // straight-line miles (haversine)
'vendor' => 17, // Product Vendors term id the driver belongs to
'driver' => 42, // driver's WP user id
'driver_lat' => 30.26715, // driver's last reported position (_user_lat)
'driver_lon' => -97.74306, // (_user_lon)
)
How the default handler works
The ride-share plugin registers its own handler on this filter (mam_ride_share_fuctions::get_available_drivers_for_lat_lon). It walks every Product Vendors vendor (filterable via mam_wc_ride_share_vendors_for_trip), collects users whose parent_pv_account_id points at the vendor, and keeps those who are on duty (punched in today, WP timezone) and within $max_distance straight-line miles of the point. Without WooCommerce Product Vendors active it returns the input unchanged.
Two things it deliberately does not do (booking adds them later): zip-code service-area matching, and Mapbox routing distance. It is the cheap “is anyone roughly nearby?” check — the home screen uses it to decide whether to show the Order Ride button at all.
Calling it
$drivers = apply_filters( 'get_available_drivers_for_lat_lon', array(), $lat, $lon, 15 );
if ( ! empty( $drivers ) ) {
$nearest = $drivers[0]; // ['driver' => user id, 'distance' => miles, ...]
}
Replacing or augmenting the result
Hook at a later priority (the built-in handler runs at 10) to filter, re-rank, or add drivers:
add_filter( 'get_available_drivers_for_lat_lon', function ( $drivers, $lat, $lon, $max ) {
// e.g. drop drivers flagged unavailable in your own system
return array_values( array_filter( $drivers, function ( $d ) {
return ! get_user_meta( $d['driver'], 'my_suspended_flag', true );
} ) );
}, 20, 4 );
Notes
- Legacy name: the hook predates the
mam_-prefix convention — the name is generic, so make sure nothing else in your stack uses the same hook for a different contract. - Distance here is straight-line; the booking flow re-ranks the matched vendor’s drivers by Mapbox routing distance, so the two can disagree near the radius edge.
Related articles
- Plugin: mam-woocommerce-ride-share
- Recipe: Set up a ride-share service
- Recipe: Driver home screen and duty toggle
Metadata
| Field | Value |
|---|---|
| Article type | Hook Reference |
| Plugin slug | mam-woocommerce-ride-share |
| Applies to plugin version | 1.3.1+ |
| Category | Extending MAM Suite |
| Hook type | filter |
| Audience | PHP developer |
| Last verified | 2026-06-10 |
