[英]How to display dynamic text in magento static block depending on time and day of week?
In a static block in magento I want to display a dynamic message depending on the day of the week and the time. 我想在magento的静态块中显示动态消息,具体取决于星期几和时间。
It's for customers, so they know when customer support is open and when it is closed. 它是针对客户的,因此他们知道客户支持的开放时间和关闭时间。
For example: I want to display: "Now Open" on monday - fridays from 09:00 till 17:00. 例如:我想在星期一显示:“现在开放”-星期五从09:00到17:00。 On saturday, sunday and on monday - friday from 17:01 untill 08:59 I want to display the text: "Now closed". 在星期六,星期日和星期一-星期五从17:01到08:59,我要显示文本:“ Now close”。
Is there a way to do this with javascript or any other way? 有没有办法用javascript或其他方式做到这一点?
Please keep in mind that I'm quite a noob on this matter :). 请记住,在这个问题上我是个菜鸟。
All help is very much appreciated! 非常感谢所有帮助!
I haven't provided the complete solution here because it will take certain time and effort but i could help you with some idea, so that you can achieve your requirement. 我在这里没有提供完整的解决方案,因为这需要花费一些时间和精力,但是我可以为您提供一些帮助,以便您可以满足您的要求。
The logic is : 逻辑是:
You may need to do little research on how to manipulate time in your case. 您可能需要对如何处理案件的时间进行很少的研究。 That's all. 就这样。
Try this, if you have any further problems than feel free to ask. 如果您有其他任何问题,可随时尝试。
Hope this will help. 希望这会有所帮助。
I managed to came up with another solution. 我设法提出了另一种解决方案。
Place this in HTML Head: 将其放在HTML Header中:
<style type="text/css">
#openSign.OPEN {
color: green;
background-color: yellow;
font-size: x-large;
}
#openSign.CLOSED {
color : red;
background-color: pink;
font-size: large;
}
</style>
<script type="text/javascript">
var OPENAT = 7.5; // 7:30 AM ... change as appropriate - can be fractions of an hour e.g. 7.5 = 7:30am
var CLOSEAT = 21; // 9:00 PM ... change as appropriate
function areWeOpen( ) {
var sign = document.getElementById("openSign");
var day = new Date().getDay();
var hour = new Date().getHours();
var mins = new Date().getMinutes();
hour = hour + mins/60;
if ( day >=1 && day <=5 && hour >= OPENAT && hour < CLOSEAT ) {
sign.innerHTML = "We are now OPEN";
sign.className = "OPEN";
}
else {
sign.innerHTML = "Sorry, we are now CLOSED";
sign.className = "CLOSED";
}
}
</script>
And this in the static block: 而这在静态块中:
<body onload = "areWeOpen()">
<span id="openSign"></span>
I don't know if this is a neat solution, but it works for me. 我不知道这是否是一个很好的解决方案,但是它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.