Extend: Hide Similar Locations

Problem

One of your stores may serve several zip codes. You want to display all these zip codes on the map, but leave only one entry in the results list.

Solution

Create a location per each zip code served by this store keeping the same name for each. For example, if a store named "Joe's Corner" serves 4 zip codes, create 4 locations named "Joe's Corner" for each zip code/address.

Then 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;
});

There are several ways to make use of this additional JavaScript code:

  • Add the custom code to your theme JavaScript file.
  • Or just add the custom 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.

Latest update: Version 3.8.6

Order Now

Get the Pro version for a lot more nice features.

Order Now

Download

Lite version to test on your WordPress website.

⇩ Download