insight-media / statamic-opening-hours
A Statamic addon to manage and display opening hours
Installs: 224
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:statamic-addon
Requires
- php: ^8.0
- spatie/opening-hours: ^2.13.0
- statamic/cms: ^3.3||^4.0
Requires (Dev)
- orchestra/testbench: ^7.16
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-10-15 15:41:00 UTC
README
Statamic Opening hours
Set your business' opening hours and exceptional closing times in the Statamic control panel.
Display or query the opening hours in your antler views using the provided openingHours tag.
Features
- Adds an 'opening hours' page to the CP navigation, where you can define multiple opening hours per weekday
- Add exceptional closing times, which override the default opening hours
- Display the opening hours using the provided tag
- Query for open/close status
- Query for next/previous opening hours/closing times
- Uses the Spatie Opening Hours package to perform queries
How to Install
You can search for this addon in the Tools > Addons
section of the Statamic control panel and click install, or run the following command from your project root:
composer require insight-media/statamic-opening-hours
Publish the optional config file.
php artisan vendor:publish --tag=statamic-google-opening-hours-config --force
How to Use
In the Statamic Control Panel
Set your business' opening hours in the Statamic control panel.
In your antlers templates
Use the openingHours tag to display or query opening hours:
Check if currently open:
{{ if {openingHours:isOpen} }} We are open {{ /if }}
Check if currently closed:
{{ if {openingHours:isClosed} }} We are closed {{ /if }}
Check if open on specific weekday:
{{ if {openingHours:isOpen on="tuesday"} }} We are open on tuesday {{ /if }}
Check if open on specific date:
{{ if {openingHours:isOpen on="2022-12-31"} }} We are open on 2022-12-31 {{ /if }}
Check if open at specific time:
{{ if {openingHours:isOpen at="2022-12-31 15:00:00"} }} We are open on 2022-12-31 at 15:00:00 {{ /if }}
Check if closed on specific weekday:
{{ if {openingHours:isClosed on="monday"} }} We are closed on monday {{ /if }}
Check if closed on specific date:
{{ if {openingHours:isClosed on="2023-01-02"} }} We are closed on 2023-01-02 {{ /if }}
Check if closed at specific time:
{{ if {openingHours:isClosed at="2022-12-31 22:00:00"} }} We are closed on 2022-12-31 at 22:00:00 {{ /if }}
Query opening times for specific weekday:
{{ openingHours:forDay day="monday" format="H:i" }} <div>{{ from }}-{{ to }}</div> {{ /openingHours:forDay }}
Query opening times for all weekdays:
{{ openingHours:forWeek format="H:i" }} {{ day }}: {{ hours }} <div>{{ from }}-{{ to }}</div> {{ /hours }}<br> {{ /openingHours:forWeek }}
Query opening times for specific date:
{{ openingHours:forDate date="2022-12-14" format="H:i" }} <div>{{ from }}-{{ to }}</div> {{ /openingHours:forDate }}
Query exceptional closing times:
{{ openingHours:exceptions format="H:i" }} {{ day }} {{ hours }} from {{ from }}-{{ to }} {{ /hours }} {{ if reason }}({{ reason }}){{ /if }}<br> {{ /openingHours:exceptions }}
Get next opening times
{{ openingHours:nextOpen date="{now format='Y-m-d H:i:s'}" format="Y-m-d H:i:s" }}
Get next closing times
{{ openingHours:nextClose date="{now format='Y-m-d H:i:s'}" format="Y-m-d H:i:s" }}
Get previous closing times
{{ openingHours:previousOpen date="{now format='Y-m-d H:i:s'}" format="Y-m-d H:i:s" }}
Get the amount of open time (number of hours as a floating number) between 2 dates/times.
{{ openingHours:diffInOpenHours from="2022-12-21 10:00:00" to="2022-12-21 13:00:00" }}
Get the amount of open time (number of minutes as a floating number) between 2 dates/times.
{{ openingHours:diffInOpenMinutes from="2022-12-21 10:00:00" to="2022-12-21 13:00:00" }}
Get the amount of open time (number of seconds as a floating number) between 2 dates/times.
{{ openingHours:diffInOpenSeconds from="2022-12-21 10:00:00" to="2022-12-21 13:00:00" }}
Get the amount of closed time (number of hours as a floating number) between 2 dates/times.
{{ openingHours:diffInClosedHours from="2022-12-21 10:00:00" to="2022-12-21 13:00:00" }}
Get the amount of closed time (number of minutes as a floating number) between 2 dates/times.
{{ openingHours:diffInClosedMinutes from="2022-12-21 10:00:00" to="2022-12-21 13:00:00" }}
Get the amount of minutes until opening time.
{{ openingHours:diffInClosedMinutes from="{now format='Y-m-d H:i:s'}" to="{ openingHours:nextOpen date="{now format='Y-m-d H:i:s'}" format="Y-m-d H:i:s" }" }}
Get the amount of closed time (number of seconds as a floating number) between 2 dates/times.
{{ openingHours:diffInClosedSeconds from="2022-12-21 10:00:00" to="2022-12-21 13:00:00" }}
Important: We recommend using the Antlers runtime parser when working with the openingHours tag.