I am looking to create a bespoke bit of PHP to work out based on the time of day whether a shop is open or closed.
The shop opening times are: Mon-Sat: 0700-1300, 1400-1800 (e.g. closed between 13:00 and 14:00), Sun: 0700-1230
So, I need the code to work out:
If its Mon,Tues,Wed,Thur,Fri or Sat and between 07:00 and 13:00, or between 14:00 and 18:00, or if its Sun between 07:00 and 12:30 echo
OPEN
else echo CLOSED.Cant seem to get it to work... What I have is a bunch of IF statements in isolation from each other which works - but I need it to work in one IF statement..
What I have is below:
<!-- Is it a sunday? -->
<?php if (date('l') >= Monday || Tuesday || Wednesday || Thursday || Friday || Saturday) : ?>
<p>It's not Sunday</p>
<?php $dayType = 1; ?>
<?php else : ?>
<p>It is Sunday</p>
<?php $dayType = 2; ?>
<?php endif; ?>
<!-- is it between 8 and 18? -->
<?php if ($dayType = 1 && current_time('H') >= 8 && current_time('H') < 18) : ?>
<p>Not Sunday and Open</p>
<?php $dayTypeStatus = 11; ?>
<?php else : ?>
<p>Not Sunday and Closed</p>
<?php $dayTypeStatus = 10; ?>
<?php endif; ?>
<!-- Is it between 13 and 14? -->
<?php if ($dayType = 1 && $dayTypeStatus = 11 && current_time('H') >= 13 && current_time('H') < 14) : ?>
<p>Not Sunday and Open - Lunchtime</p>
<?php $dayTypeStatusLunch = 111; ?>
<?php else : ?>
<p>Not Sunday and Open - Not Lunchtime</p>
<?php $dayTypeStatusLunch = 110; ?>
<?php endif; ?>
<!-- Is it between 8 and 12:30 on a sunday? -->
<?php if (date('l') >= Sunday && current_time('H') >= 8 && current_time('H:i') < "12:30") : ?>
<p>Sunday Open</p>
<?php else : ?>
<p>Sunday Closed</p>
<?php endif; ?>
Any ideas to make it work?
Better attempt at code is as below:
<?php if (date('l') != Sunday && current_time('H') >= 7 && current_time('H') < 18) : ?>
<p>OPEN</p>
<?php else : ?>
<p>CLOSED</p>
<?php endif; ?>
But still missing the lunchtime close element and also including the sunday opening hours check - e.g. this works to check if its not a sunday and is between 0700 and 1800.
UPDATE - think this works???
<?php if (date('l') != "Sunday" && current_time('H') >= 7 && current_time('H') < 13 || current_time('H') >= 14 && current_time('H') < 18 || date('l') == "Sunday" && current_time('H') >= 8 && current_time('H:i') < "12:30") : ?>
<p>OPEN</p>
<?php else : ?>
<p>CLOSED</p>
<?php endif; ?>