1

We use some line to display if we are open or not. For this we use this line:

<?php $weekday = Mage::getSingleton('core/date')->date('w'); ?>
<?php $hour    = Mage::getSingleton('core/date')->date('G'); ?>
<?php if ($weekday >= 1 && $weekday <= 5 && $hour >= 8.30 && $hour < 17.30) : ?>
<p>Open</p>

<?php else : ?>
<p>Closed</p>

<?php endif; ?>

But I want to expand this line, that we are closed because of a national day of the year.
How can I expand this code with some specific dates. For example 14/05/2015 and 24/05/2015 and 25/05/2015.

How can I achieve that?

3

See the date formats

Try something like this:

$weekday = Mage::getSingleton('core/date')->date('w');
$hour    = Mage::getSingleton('core/date')->date('G');
$closedDates = array('2015-05-14', '2015-05-24', '2015-05-25');
$date = Mage::getSingleton('core/date')->date('Y-m-d');
if ($weekday >= 1 && $weekday <= 5 && $hour >= 8.30 && $hour < 17.30 && !in_array($date, $closedDates)) {
 ...your magic here
}
4
  • Thanks Marius! But how do I include the line with the times of opening and day of the week from 1 to 5? – JGeer May 7 '15 at 7:40
  • @Jelle. See my update – Marius May 7 '15 at 7:42
  • Works wonderful! :) – JGeer May 7 '15 at 7:45
  • @Marius Do you know how to do this in magento 2? – Joey Dec 18 '17 at 8:13
3

You can use the Magento Mage::getSingleton('core/date')->date('Y-m-d') method to get the current date and verify that against a string with the date

<?php 
$weekday = Mage::getSingleton('core/date')->date('w');
$hour    = Mage::getSingleton('core/date')->date('G');
$date    = Mage::getSingleton('core/date')->date('Y-m-d');
if ($weekday >= 1 && $weekday <= 5 || $date == '2015-05-20') : ?>

Sidenote This does not take into account the timezone of the user, it's based on the servers timezone so for an international shop (with clients in multiple timezones) you're better off using Javascript

[EDIT] Thanks to Marius for correcting the method used for retrieving the date

1
  • Thanks Sander! I updated my request, because I do not know how to implement this in our situation. – JGeer May 7 '15 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.