[insert_php]
// ——– PHP STORE HOURS ———
// ———- Version 2.0 ———–
// ——– BY CORY ETZKORN ———
// ——– coryetzkorn.com ———
// ——– EDIT FOLLOWING SECTION ONLY ———
// Set your timezone (codes listed at http://php.net/manual/en/timezones.php)
// Delete the following line if you’ve already defined a timezone elsewhere.
date_default_timezone_set(‘Australia/Sydney’);
// Define daily open hours
// Must be in 24-hour format, separated by dash
// If closed for the day, set to 00:00-00:00
// If open multiple times in one day, enter time ranges separated by a comma
// If open late (ie. 6pm – 1am), add hours after midnight to the next day (ie. 00:00-1:00)
$hours = array(
‘mon’ => array(‘9:00-17:30’),
‘tue’ => array(‘9:00-17:30’),
‘wed’ => array(‘9:00-17:30’),
‘thu’ => array(‘9:00-17:30’),
‘fri’ => array(‘9:00-17:30’),
‘sat’ => array(‘9:00-17:30’),
‘sun’ => array(’00:00-00:00′)
);
// Optional: add exceptions (great for holidays etc.)
// Works best with format day/month
// Leave array empty if no exceptions
$exceptions = array(
‘New Years Day’ => ‘1/1’,
‘Anzac Day’ => ’25/4′,
‘Christmas Day’ => ’25/12′,
‘Boxing Day’ => ’26/12′
);
// Place HTML for output below. This is what will show in the browser.
// Optional: use %open% and %closed% to add dynamic times to your open message.
// Warning: %open% and %closed% will NOT work if you have multiple time ranges assigned to a single day.
// Optional: use %day% to make your “closed all day” message more dynamic.
// Optional: use %exception% to make your exception messages dynamic.
$open_now = ”
Yes, we’re open! Today’s hours are %open% until %closed%.
“;
$closed_now = ”
Sorry, we’re closed. Today’s hours are %open% until %closed%.
“;
$closed_all_day = ”
Sorry, we’re closed on %day%.
“;
$exception = ”
Sorry, we’re closed for %exception%.
“;
// Enter custom time format if using %open% and %closed%
// (options listed here: http://php.net/manual/en/function.date.php)
$time_format = ‘g:ia’;
// The %day% shortcode is replaced by these days of the week.
// Edit these if you’d like to use a language other than English.
$days = array(
‘mon’ => ‘Mondays’,
‘tue’ => ‘Tuesdays’,
‘wed’ => ‘Wednesdays’,
‘thu’ => ‘Thursdays’,
‘fri’ => ‘Fridays’,
‘sat’ => ‘Saturdays’,
‘sun’ => ‘Sundays’
);
// ——– END EDITING ——–
$day = strtolower(date(“D”));
$today = strtotime(‘today midnight’);
$now = strtotime(date(“G:i”));
$is_open = 0;
$is_exception = false;
$is_closed_all_day = false;
// Check if closed all day
if($hours[$day][0] == ’00:00-00:00′) {
$is_closed_all_day = true;
}
// Check if currently open
foreach($hours[$day] as $range) {
$range = explode(“-“, $range);
$start = strtotime($range[0]);
$end = strtotime($range[1]);
if (($start <= $now) && ($end >= $now)) {
$is_open ++;
}
}
// Check if today is an exception
foreach($exceptions as $ex => $ex_day) {
$ex_day = strtotime($ex_day);
if($ex_day === $today) {
$is_open = 0;
$is_exception = true;
$the_exception = $ex;
}
}
// Output HTML
if($is_exception) {
$exception = str_replace(‘%exception%’, $the_exception, $exception);
echo $exception;
} elseif($is_closed_all_day) {
$closed_all_day = str_replace(‘%day%’, $days[$day], $closed_all_day);
echo $closed_all_day;
} elseif($is_open > 0) {
$open_now = str_replace(‘%open%’, date($time_format, $start), $open_now);
$open_now = str_replace(‘%closed%’, date($time_format, $end), $open_now);
echo $open_now;
} else {
$closed_now = str_replace(‘%open%’, date($time_format, $start), $closed_now);
$closed_now = str_replace(‘%closed%’, date($time_format, $end), $closed_now);
echo $closed_now;
}
[/insert_php]
Monday to Friday 9am – 5:30pm
Saturday 9am – 4.00pm
Sunday Closed