Documentationfor Business Hours WP
Description
Function within_business_hours() to check if current date/time is within business hours.
Returns true if within business hours. Business hours are defined via two ACF Repeaters. First repeater defines regular business hours per weekday.
Second Repeater defines exceptions to those regular business hours for holidays. Holidays can be defined as a date only (closed all day) or individual business hours for that day.
Import
The package contains three files:
Content | Filename | Import To |
---|---|---|
1) ACF field group configuration | acf-export-business_hours.json | ACF Pro (Advanced Custom Fields Pro) |
2) ACF Options Page configuration | acf-options-page.code-snippets.json | Code Snippets (or other PHP Snippet Plugin) |
3) Function within_business_hours() | business-hours.code-snippets.json | Code Snippets (or other PHP Snippet Plugin) |
Import those files to ACF resp. Code Snippets (or Alternative) in the listed order.
ACF Configuration
The ACF fields can be added to an options page (ACF Pro) or to a single post (ACF free). ACF location is configured with $acf_location.
The field names for the ACF Repeater can be configured with $acf_weekdays and $acf_holidays.
The Repeater sub field names are hard coded and can't be changed by configuration.
The ACF JSON configuration is part of the delivery.
ACF Repeater Weekdays
Repeater business_hours_weekdays
- weekday
Type: Select
Values:
- 1 : Montag
- 2 : Dienstag
- 3 : Mittwoch
- 4 : Donnerstag
- 5 : Freitag
- 6 : Samstag
- 0 : Sonntag
Return: Value
- start
Type TimePicker
Return: H:i
- end
Type: Time Picker
Return: H:i
Weekdays are evaluated by number, not by weekday name. Hence, weekday names can betranslated.
ACF Repeater Holidays
Repeater business_hours_holidays
- date
Type: DatePicker
Return: Ymd
- start
Type TimePicker
Return: H:i
- end
Type: Time Picker
Return: H:i
Defining Business Hours
On your ACF options page you can now define your regular business hours for each weekday, and your deviating opening hours on holidays.
If holiday start and end fields are empty, it's evaluated as "closed". If start and end fields are defined those are evaluated as deviating business hours.
Function: within_business_hours
The function evaluates dates and times based on server time, using the timezone defined in WordPress settings.
The function code is part of the delivery as PHP and JSON export (for Code Snippets).
Using Function in an Oxygen Code Block
The function within_business_hours() can be used in a Code Block like this:
<?php
if (function_exists('within_business_hours')):
echo 'We're '.(within_business_hours() ? 'open' : 'closed').'!';
endif;
?>
Using Function in an Oxygen Condition
Using Function in a Bricks Code Element
The function within_business_hours() can be used in a Code Block like this:
<?php
if (function_exists('within_business_hours')):
echo 'We're '.(within_business_hours() ? 'open' : 'closed').'!';
endif;
?>