Help Appreciated | Modify Code Snippet to Add Holidays
-
The code snippet provided below generates the shortcode “[business_hours]” which can be used to display a message on the front end indicating if a business is open or closed based on normal business hours.
We would like to modify it to add holidays together with the front end message: “CLOSED FOR THE HOLIDAY”
We do not need to use this plugin in its entirety.
Any experts available to help?
Thank you!
PS: We tried to integrate portions of the code provided here, but couldn’t get them to work.
———————-
function business_hours_shortcode($atts) {
if (is_page ('contact')) {
// Set timezone - change this to match your own.
date_default_timezone_set('America/Chicago');
// An array of your opening hours.
$opening_hours = array(
'Monday' => array('07:30', '17:30'),
'Tuesday' => array('07:30', '17:30'),
'Wednesday' => array('07:30', '17:30'),
'Thursday' => array('07:30', '17:30'),
'Friday' => array('07:30', '17:30'),
'Saturday' => array('Closed'),
'Sunday' => array('Closed'),
);
// Get current day and time.
$current_day = date('l');
$current_time = date('H:i');
// Get today's opening hours.
$today_hours = $opening_hours[$current_day];
// Check if we have opening hours for today.
if (!isset($today_hours) || count($today_hours) < 2) {
return '<span style="color:#ffffff;background-color:#e14d43;padding:6px 12px;border-radius:3px;">CLOSED TODAY</span>';
}
// Check if current time is between opening hours.
if ($current_time >= $today_hours[0] && $current_time <= $today_hours[1]) {
return '<span style="color:#ffffff;background-color:#00c853;padding:6px 12px;border-radius:3px;">CURRENTLY OPEN</span>';
} else {
return '<span style="color:#ffffff;background-color:#e14d43;padding:6px 12px;border-radius:3px;">CURRENTLY CLOSED</span>';
}
}
}
add_shortcode('business_hours', 'business_hours_shortcode');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.