wpsl_no_results

  1. Description
  2. Usage
  3. Changelog
  4. Source File

Description

This filter allows you to create a custom HTML block informing the user that the search returned no results. It replaces the text from the No results found field on Store Locator > Settings > Labels, under Other labels. By default that text is followed by “Please adjust your search and try again.” The filter replaces the whole message.

If If no results are found, then show the nearest location ignoring the search radius? is enabled on Store Locator > Settings > Search, the filter value also replaces the message with the “show the nearest location” link. Visitors then don’t get the option to search for the nearest location.

The filter only applies when a search returns no locations. When the entered address itself can’t be found, the text from the Labels setting is shown.

Usage

add_filter( 'wpsl_no_results', 'custom_no_results' );
function custom_no_results() {
$output = '<h2>No results found!</h2>';
$output .= '<p>Please contact us at <a href="tel:123456">+123456</a> or <a href="mailto:support@mydomain.com">support@mydomain.com</a>.</p>';
$output .= '<img src="http://mydomain.com/my-logo.jpg" alt="business logo"/>';
return $output;
}

The HTML is shown in the results list, inside <li class="wpsl-no-results-msg">.

To change the message in JavaScript, use the wpslNoResultsMsg hook with wp.hooks.addFilter. Its only argument is the message that is about to be shown: the value of this filter, the “show the nearest location” message, or the Labels text. Return the HTML to show. If the returned HTML still has the link with the id wpsl-search-nearest-btn, that link still searches for the nearest location.

Changelog

VersionDescription
3.0Moved to includes/frontend/assets/class-resources.php. The filter value also replaces the message of the new "show the nearest location" option. New JavaScript hook wpslNoResultsMsg to change the message in the browser.
2.2Introduced.

Source File

This filter is located in /includes/frontend/assets/class-resources.php.

Placement

The code needs to be placed in the functions.php file inside your active theme folder.