Extend: Hide Similar Locations
This article is a part of the series for tech-savvy web developers out there who are looking to further enhance Locatoraid store locator features and options. We assume that the reader of the series is familiar with JavaScript and/or PHP.
Problem
One of your store locations may serve several zip codes. You want to display all of these zip codes on the map, but in the results list you would like to have just one entry.
Solution
For each zip code create multiple locations with the same name, each location serving a specific zip code. For example, if your store named Joe's Corner can serve 4 different zip codes, create 4 locations named Joe's Corner for each zip code.
Then you will need to add the following JavaScript code:
var locatoraidAlreadyShown = {};
// reset for a new search result
document.addEventListener( 'locatoraid-get-results', function(){
locatoraidAlreadyShown = {};
});
// listen to render
document.addEventListener( 'locatoraid-render-in-list', function(e){
var thisName = e.payload.data('location')['name'];
// already displayed?
if( locatoraidAlreadyShown.hasOwnProperty(thisName) ){
var $div = e.payload;
$div.hide();
}
locatoraidAlreadyShown[thisName] = true;
});
How to add this piece of custom JavaScript code to your WordPress store locator front-end? There are several ways to do it:
- Locate your current WordPress theme JavaScript file and paste this custom code to it.
-
Or manually add this JavaScript code directly to the content of the page with Locatoraid
[locatoraid]
shortcode. Do not forget to wrap the JavaScript code with the <script> and </script> tags.