Small FREE Magento 2 extension for adding time and day
dependend info in your store
In this case I use the Ultimo Magento theme from Infortis. But it
will work in any Magento 2 theme. I have created 1 phtml
with the javascript. I added 1 static block to pull the phtml
into the header. I have added some css to get the correct
color.
The javascript can be
downloaded here.
Now on a weekday (Monday to Friday) from 09:00 until 17:00
the header will show “Open”
And in the weekend you will see that the store is closed.
I have also added some icons from fontawesome.io to
create the phone and the clock.
In the static block I have added;
{{block class="MagentoFrameworkViewElementTemplate"
name="openclosed"
template="Magento_Theme::html/openclosed.phtml"}}
The static block it self is being added to the header
by a widget;
On the server I have added a file called openclosed.phtml to
the theme;
In this file you can find the actual java
script;
<script type="text/javascript">
<!--
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var day = currentTime.getDay()
//open hours between 9am and 17pm and Monday till Friday
if ((hours>9 && hours<17) && (day>0
&& day<6)){
document.write("<span
class='time-open'>Vragen?<br><i class='fa fa-phone'
aria-hidden='true'></i> 0346 700 230<br> <i
class='fa fa-clock-o' aria-hidden='true'></i> Nu open
tot 17:00 uur</span>");
}
else{
document.write("<span
class='time-open'>Vragen?<br><i class='fa fa-phone'
aria-hidden='true'></i> 0346 700 230<br> <i
class='fa fa-clock-o' aria-hidden='true'></i> Nu
telefonisch gesloten<br>Bereikbaar van ma t/m vr 09:00
t/m 17:00 uur</span>")
}
//-->
</script>
For more info on how to set your own time and other settings
please visit; http://www.w3schools.com/jsref/jsref_operators.asp