Show the Opening Hours in the Search Results

Since WP Store Locator 3.0 you don’t need any code for this. The opening hours are shown below the address in the search results by default, through the “Location(s) of opening hours” setting under Store Locator > Settings > User Experience. On sites upgraded from version 2, nothing may be selected there yet, so check that “Below the address in the search results” is selected.

The same setting can also place the opening hours in the “more info” section of the search results, or in the marker pop-ups. On the same tab, “Show the current open / closed status?” adds whether the store is open right now, and “Hide days marked as closed in the opening hours?” leaves out the closed days. If “Hide the opening hours?” is enabled in the Store Editor section of the settings page, the opening hours aren’t shown anywhere.

If you build the search results template yourself with the wpsl_listing_template filter, the v3 example on that page already includes the opening hours, following the same setting.

For a custom template that doesn’t use the setting, include the ‘hours’ data in your template code:

// The opening hours, only for stores that have them.
$listing_template .= "\t\t" . '<% if ( typeof hours !== "undefined" && hours ) { %>' . "\r\n";
$listing_template .= "\t\t" . '<div><%= hours %></div>' . "\r\n";
$listing_template .= "\t\t" . '<% } %>' . "\r\n";

The opening hours come with their own markup, a table or a list, so they’re wrapped in a div instead of a p. The typeof check keeps the template working for stores without opening hours, and when “Hide the opening hours?” is enabled.

Changing the “Location(s) of opening hours” setting clears the store locator cache for you, and template changes show up straight away. If the opening hours still don’t show up, clear the cache under Store Locator > Settings > Tools > Autoload cache, and the cache of your caching plugin if you use one.