I am looking to disable the location/distance filter from the code programmatically using certain conditions.
You can see what I am trying to achieve on the URL:
hidden link
Basically, when the location is updated in the field, I am checking whether it is a country or a state, or another type of location.
1. If it is country or state, I want the query to only do a custom field search using the state and country fields and ignore the location field.
2. If it is another location type (city, postcode, street, user's location), I want to so the default search with that location and a set distance of 30kms.
For this purpose, I have added two text fields which will populate the state and country if you search for a name of a state, province or country, for example "Ontario, Canada" or "Australia", or "Victoria, Australia". The fields are visible for testing purposes now but I will eventually hide them. These fields are also linked to "geo_state" and "geo_country" URL parameters.
I have two issues:
1. I already wrote JS for them to be populated when the location field is updated. Unfortunately, the fields appear and then are reset instantly. I applied some delay of "1400ms" but it only works on and off, so it is not reliable. You can check my JS code here:
https://pastebin.com/aATsHYJy
I am already saving the state and country in the custom field and the search works great whenever the fields get populated properly or if you manually enter state and country in those fields. Is there any way to prevent the state and country fields from being reset in the JS?
2. My second issue is that I want to unhook/remove the location/distance filter when the aforementioned state and country fields are being queried, i.e. when the "geo_country" URL param exists, I want the query to ignore the "toolset_maps_distance_center" and "toolset_maps_distance_radius" URL parameters and search as if the location field is empty. How do I do that programatically?