Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is my solution:</p> <p><strong>INPUT DATA:</strong></p> <blockquote> <pre><code>$meta = array( 'opening_hours_mon' =&gt; '9am - 8pm', 'opening_hours_tue' =&gt; '9am - 2am', 'opening_hours_wed' =&gt; '8:30am - 2am', 'opening_hours_thu' =&gt; '9am - 3pm', 'opening_hours_fri' =&gt; '8:30am - 11am', 'opening_hours_sat' =&gt; '9am - 3pm, 5pm - 2am', 'opening_hours_sun' =&gt; 'closed' </code></pre> <p>);</p> </blockquote> <p>current_time( 'timestamp' ) (as said author) analog of <code>time()</code> in WordPress <br><strong>And solution:</strong></p> <blockquote> <pre><code> $now = (int) current_time( 'timestamp' ); $day = strtolower(date('D', $now)); $yesterday = strtolower(date('D', strtotime('-1 day'))); $days = array( 'yesterday' =&gt; $meta['opening_hours_'.$yesterday], 'today' =&gt; $meta['opening_hours_'.$day], ); $status = false; foreach($days as $when=&gt;$times) { $parts = explode(',',$times); foreach($parts as $p) { if($p == 'closed') break; else{ list($b,$e) = explode('-',$p); $b = strtotime("$when $b"); $e = strtotime("$when $e"); if($b &gt; $e) $e += strtotime("$when $e +1 day");; if($b &lt;= $now &amp;&amp; $now &lt;= $e) { $status =true; break; } } } } </code></pre> </blockquote> <p><strong>FOR TESTING:</strong><br> you may change first 3 lines to followings:</p> <blockquote> <pre><code>$now = (int) strtotime('today 3:00am'); $day = strtolower(date('D', $now)); $yesterday = strtolower(date('D', strtotime('yesterday 3:00am'))); </code></pre> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload