wpsl_hour_shortcode_defaults

  1. Description
  2. Parameters
  3. Usage
  4. Changelog
  5. Source File
  6. Related

Description

This filter allows you to change the default attributes of the [wpsl_hours] shortcode.

Most defaults come from the User Experience settings on Store Locator > Settings > User Experience. Change the setting first if you want the same behaviour in the search results. Use this filter if you only want to change the [wpsl_hours] output.

You can also set the attributes on a single shortcode, for example [wpsl_hours id="123" current_status="true" hide_closed="true"]. Attributes on the shortcode override the defaults from this filter.

The shortcode outputs nothing when “Hide the opening hours?” is enabled on Store Locator > Settings > Store Editor.

Parameters

$shortcode_defaults - (array) The default shortcode attributes.

KeyDefaultDescription
id''The ID of the store. On a store page it defaults to the current store. Anywhere else the ID is required.
hide_closedThe "Hide days marked as closed in the opening hours?" setting.Skip the days that are set to closed.
current_statusThe "Show the current open / closed status?" setting.Show the current open / closed status above the opening hours.
expand_statustrue when both "Show the current open / closed status?" and "Make the current opening status expandable in the search results?" are enabled.Hide the opening hours behind the status until the visitor clicks it. Only works together with current_status.

Usage

This example always shows the current open / closed status above the opening hours, and keeps the full list of hours visible below it. The search results still follow the User Experience settings.

add_filter( 'wpsl_hour_shortcode_defaults', 'custom_hour_shortcode_defaults' );
function custom_hour_shortcode_defaults( $shortcode_defaults ) {
// Always show the current open / closed status above the opening hours.
$shortcode_defaults['current_status'] = true;
// Keep the full list of opening hours visible below the status.
$shortcode_defaults['expand_status'] = false;
return $shortcode_defaults;
}

Changelog

VersionDescription
3.0Moved to includes/core/hours/class-service.php. Added the current_status and expand_status keys. The hide_closed default now comes from the "Hide days marked as closed in the opening hours?" setting instead of the wpsl_hide_closed_hours filter.
2.0Introduced.

Source File

This filter is located in /includes/core/hours/class-service.php.

Placement

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