Ciao a tutti. Sto modificando la homepage del sito della mia attività e stavo integrando la funzione per vedere se, all'ora in cui si è adesso, questa sia aperta o chiusa.
Ho creato una tabella con gli orari e nella terza colonna ci deve venir scritto "Aperto" o "Chiuso" dinamicamente nonostante l'ora.
Ho fatto una ricerca su internet e ho trovato un pezzo di codice e l'ho modificato in parte:
Quando ho integrato questo codice il primo giorno funzionava tutto alla grande poi dal secondo giorno in poi la scritta rimane su "Chiuso" per tutto il tempo, 24h su 24, nonostante l'orario in cui è aperta. Non capisco cosa ci sia di sbagliato
Chiedo un vostro aiuto per metterlo a posto. Grazie mille.
Ho creato una tabella con gli orari e nella terza colonna ci deve venir scritto "Aperto" o "Chiuso" dinamicamente nonostante l'ora.
Ho fatto una ricerca su internet e ho trovato un pezzo di codice e l'ho modificato in parte:
PHP:
<?php
$storeSchedule = [
'Mon' => ['08:15 AM' => '12:15 AM', '03:00 PM' => '07:00 PM'],
'Tue' => ['08:15 AM' => '12:15 AM', '03:00 PM' => '07:00 PM'],
'Wed' => ['08:15 AM' => '12:15 AM', '03:00 PM' => '07:00 PM'],
'Thu' => ['08:15 AM' => '12:15 AM'],
'Fri' => ['08:15 AM' => '12:15 AM', '03:00 PM' => '07:00 PM'],
'Sat' => ['08:15 AM' => '12:15 AM', '03:00 PM' => '07:00 PM']
];
$timestamp = time();
$status = 'Chiuso';
$currentTime = (new DateTime())->setTimestamp($timestamp);
foreach ($storeSchedule[date('D', $timestamp)] as $startTime => $endTime) {
$startTime = DateTime::createFromFormat('h:i A', $startTime);
$endTime = DateTime::createFromFormat('h:i A', $endTime);
if (($startTime < $currentTime) && ($currentTime < $endTime)) {
$status = 'Aperto';
break;
}
}
$jd=gregoriantojd(date("m"),date("d"),date("Y"));
if (jddayofweek($jd,1) == 'Monday' || jddayofweek($jd,1) == 'Tuesday' || jddayofweek($jd,1) == 'Wednesday') {
if ($status == "Aperto") {
echo "<th><p style='margin-top:0%;'>Lun-Mer:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td><b><font color='green'>Aperto<br><font color='white'>.</font></font></b></td></tr>";
echo "<th><p style='margin-top:0%;'>Gio:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15</p></td>";
echo "<td></td></tr>";
echo "<th><p style='margin-top:0%;'>Ven-Sab:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td></td></tr>"; }
else {
echo "<th><p style='margin-top:0%;'>Lun-Mer:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td><b><font color='red'>Chiuso<br><font color='white'>.</font></font></b></td></tr>";
echo "<th><p style='margin-top:0%;'>Gio:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15</p></td>";
echo "<td></td></tr>";
echo "<th><p style='margin-top:0%;'>Ven-Sab:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td></td></tr>"; }
}
if (jddayofweek($jd,1) == 'Thursday') {
if ($status == "Aperto") {
echo "<th><p style='margin-top:0%;'>Lun-Mer:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td></td></tr>";
echo "<th><p style='margin-top:0%;'>Gio:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15</p></td>";
echo "<td><b><font color='green'>Aperto</font></b></td></tr>";
echo "<th><p style='margin-top:0%;'>Ven-Sab:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td></td></tr>"; }
else {
echo "<th><p style='margin-top:0%;'>Lun-Mer:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td></td></tr>";
echo "<th><p style='margin-top:0%;'>Gio:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15</p></td>";
echo "<td><b><font color='red'>Chiuso</font></b></td></tr>";
echo "<th><p style='margin-top:0%;'>Ven-Sab:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td></td></tr>";}
}
if (jddayofweek($jd,1) == 'Friday' || jddayofweek($jd,1) == 'Saturday') {
if ($status == "Aperto") {
echo "<th><p style='margin-top:0%;'>Lun-Mer:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td></td></tr>";
echo "<th><p style='margin-top:0%;'>Gio:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15</p></td>";
echo "<td></td></tr>";
echo "<th><p style='margin-top:0%;'>Ven-Sab:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td><b><font color='green'>Aperto<br><font color='white'>.</font></font></b></td></tr>"; }
else {
echo "<th><p style='margin-top:0%;'>Lun-Mer:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td></td></tr>";
echo "<th><p style='margin-top:0%;'>Gio:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15</p></td>";
echo "<td></td></tr>";
echo "<th><p style='margin-top:0%;'>Ven-Sab:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td><b><font color='red'>Chiuso<br><font color='white'>.</font></font></b></td></tr>";}
}
if (jddayofweek($jd,1) == 'Sunday') {
echo "<th><p style='margin-top:0%;'>Lun-Mer:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td></td></tr>";
echo "<th><p style='margin-top:0%;'>Gio:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15</p></td>";
echo "<td></td></tr>";
echo "<th><p style='margin-top:0%;'>Ven-Sab:</p></th>";
echo "<td><p style=' margin-left:10px;'>08:15 - 12:15<br>15:00 - 19:00</p></td>";
echo "<td></td></tr>";
}
?>
Quando ho integrato questo codice il primo giorno funzionava tutto alla grande poi dal secondo giorno in poi la scritta rimane su "Chiuso" per tutto il tempo, 24h su 24, nonostante l'orario in cui è aperta. Non capisco cosa ci sia di sbagliato
Chiedo un vostro aiuto per metterlo a posto. Grazie mille.