Support » Plugin: WP Store Locator » Find Closest Location

  • We have a client that is requesting, that when a user searches, if there’s no location within the specified radius, for it to jump to the closest location instead… is this possible within the plugin, or to your knowledge, the Google Maps API?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    There are two possible ways to make this work, but neither one is easy to implement.

    1) You can edit the wpsl-gmap.js file, and inside the function makeAjaxRequest you check if data is returned. If not, then you start a new request with a custom param included. You can then use that param in combination with the wpsl_sql filter to write a custom query that searches for the nearest location.

    2) Not 100% sure this is possible, but I think you can make the SQL query check if it returns results, and if not, then adjust the query. But this is beyond my SQL skills. This will require the same wpsl_sql filter.

    Thank you for the quick feedback, Tijmen! I’ll look into your suggestions, and let you know what I come up with.

    hello Tijmen!
    I was able to accomplish our goal, without editing any of the plugin’s code.

    Hooked into wpsl_store_data and if no search results are found, I perform the search again, but remove the WHERE/HAVING clause from the MySQL query, and once I know the closest location, I use PHP code to select the stores within a certain radius of that location.

    Was actually simpler than I expected it would be; excited that it was able to be accomplished without editing the plugin’s files.

    Hi crstauf! Would you mind sharing how you did it? I need to do the exact same thing and would appreciate your guidance. Thanks!

    hey Jessn. unfortunately, I can’t share the code directly (client work), but the post I made above describes the steps I took, and should point you in the right direction.

    the plugin is built using MySQL to select the closest store locations, so all that’s necessary is to grab all the store locations, and use PHP to select locations.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Find Closest Location’ is closed to new replies.