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.
Parameters
$shortcode_defaults - (array) The default shortcode attributes.
| Key | Default | Description |
|---|---|---|
id | '' | The ID of the store. On a store page it defaults to the current store. Anywhere else the ID is required. |
hide_closed | The "Hide days marked as closed in the opening hours?" setting. | Skip the days that are set to closed. |
current_status | The "Show the current open / closed status?" setting. | Show the current open / closed status above the opening hours. |
expand_status | true 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
| Version | Description |
|---|---|
| 3.0 | Moved 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.0 | Introduced. |
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.