Description
This filter allows you to include additional data after the existing meta data from the “Store Details” section is collected.
Fields you add in Store Locator > Settings > Fields Manager are added to the store data automatically, under the field name. You don’t need this filter for them.
The filter runs for every location in the search results. It doesn’t run for online stores, which are added when Include online stores? is checked on Store Locator > Settings > Store Editor.
Parameters
$store_meta - (array) The existing store meta data.
$store_id - (int|string) The id of the current store. A search around a location passes it as a numeric string, other searches as an integer. Use (int) $store_id if you compare it with another id.
Usage
| add_filter( 'wpsl_store_meta', 'custom_store_meta', 10, 2 ); | |
| function custom_store_meta( $store_meta, $store_id ) { | |
| $store_meta['extra_data'] = 'your extra data'; | |
| return $store_meta; | |
| } |
If Load locations on page load is on, the locations shown on page load can come from a cache. After you add the filter, go to Store Locator > Settings > Tools and click Clear cache next to Autoload cache.
Changelog
| Version | Description |
|---|---|
| 3.0 | Moved to includes/frontend/store/class-data.php. Fields Manager fields are added to the store data automatically. $store_id is an integer for searches that don't search around a location. Online stores don't pass through the filter. |
| 2.0 | Introduced. |
Source File
This filter is located in /includes/frontend/store/class-data.php.
Placement
The code needs to be placed in the functions.php file inside your active theme folder.