Signature
apply_filters( 'mam_wc_geofilters_locations', array $locations );
| Parameter | Type | Description |
|---|---|---|
$locations |
array | Array of location entries. Each entry has text, lat, and lon. |
Returns: array — the modified $locations array. You must return it.
Purpose
Adds, removes, or rewrites entries in the geofilter location list when the plugin is using its built-in default-list path. This is the right hook when you want to extend the default 55-city list — for example, add markets the app serves that aren’t in the built-in set, or strip the list down to a small handful for a regional app.
If you want to replace the list with data from a completely different source (a custom post type, an external API, GeoDirectory taxonomy), use Hook: mam_geofilter_list instead.
When it runs
Inside mam_geofilters_list::add_geofilters() (includes/geofilters-cities-list.php), in this order:
- The default 55-city list is built.
- Cities listed in the
mam_geofilters_hiddenadmin option are removed. mam_wc_geofilters_locationsruns. ← your callback- The list is sorted alphabetically by
text. - Entries with
lat == 0orlon == 0are dropped. - A Nearby entry is prepended if the request includes
actual_lat.
This means your additions are visible to the admin show/hide UI on the next page load, but only after a request has populated the list once.
Entry shape
[
'text' => 'Rochester, NY',
'lat' => '43.1566',
'lon' => '-77.6088',
]
lat and lon may be strings or floats. The plugin treats them as strings in the default list.
Example: add a custom city
add_filter( 'mam_wc_geofilters_locations', 'my_app_add_rochester' );
function my_app_add_rochester( $locations ) {
$locations[] = [
'text' => 'Rochester, NY',
'lat' => '43.1566',
'lon' => '-77.6088',
];
return $locations;
}
Example: trim to a regional subset
add_filter( 'mam_wc_geofilters_locations', 'my_app_west_coast_only' );
function my_app_west_coast_only( $locations ) {
$allowed = [ 'San Jose', 'Oakland', 'Los Angeles', 'San Diego', 'San Francisco', 'Sacramento', 'Seattle', 'Portland' ];
return array_values( array_filter(
$locations,
function ( $loc ) use ( $allowed ) {
return in_array( $loc['text'], $allowed, true );
}
) );
}
Gotchas
- Bypassed when
mam_geofilter_listis registered. The phone-data pipeline callshas_filter( 'mam_geofilter_list' )first; if any callback is attached there (notably frommam-geodirectory), the entire default-list path is skipped and this filter never fires. If your additions disappear after activating another plugin, that’s why. latorlonof0is silently dropped. A late line in the list builder filters out any entry with a zero coordinate. If you’re returning data from a database where missing coords default to0, you’ll lose those entries with no warning.- Always return the array. Forgetting
return $locations;strips the entire list. - Don’t add duplicates by
text. The admin show/hide UI keys ontext. Two entries with the sametextproduce confusing checkbox behavior. - Runs on every phone-data request. Keep the callback fast. If you’re pulling from a database or external API, cache the result.
Verification
This article was last verified against:
- Plugin:
mam-geofiltersv2.1.1 - Source:
mam-geofilters/includes/geofilters-cities-list.php - Source:
mam-geofilters/includes/phone-manager.php
Re-verify whenever the order of operations in mam_geofilters_list::add_geofilters() changes, the zero-coordinate drop at the end of that method changes, or the has_filter( 'mam_geofilter_list' ) gating in phone-manager.php is replaced.
Related articles
- Plugin overview: mam-geofilters
- Recipe: Manage the city list — admin-side equivalent for hiding cities
- Hook: mam_geofilter_list — use this instead if you want full control of the list
- Hook: mam_force_geofilters
- Hook: mam_geofilter_radius
Metadata
| Field | Value |
|---|---|
| Article type | Hook Reference |
| Plugin slug | mam-geofilters |
| Applies to plugin version | 2.1.1+ |
| Category | Extending MAM Suite |
| Hook type | filter |
| Audience | PHP developer |
| Last verified | 2026-04-30 |
