Hook: mam_wc_geofilters_locations

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:

  1. The default 55-city list is built.
  2. Cities listed in the mam_geofilters_hidden admin option are removed.
  3. mam_wc_geofilters_locations runs. ← your callback
  4. The list is sorted alphabetically by text.
  5. Entries with lat == 0 or lon == 0 are dropped.
  6. 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_list is registered. The phone-data pipeline calls has_filter( 'mam_geofilter_list' ) first; if any callback is attached there (notably from mam-geodirectory), the entire default-list path is skipped and this filter never fires. If your additions disappear after activating another plugin, that’s why.
  • lat or lon of 0 is 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 to 0, 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 on text. Two entries with the same text produce 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-geofilters v2.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.


  • 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
Contents

    Need Support?

    Can’t find the answer you’re looking for? Don’t worry we’re here to help!