Created
January 18, 2022 18:50
-
-
Save josephclaytonhansen/a9f9e4ad9655c9d248e668e651a41315 to your computer and use it in GitHub Desktop.
Javascript Dynamic Hours (ideal for Wordpress)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
window.onload = function() { | |
var today = new Date(); | |
var day = today.getDay(); | |
if (today.getMinutes() > 9) { | |
var hourm = today.getHours() + "." + today.getMinutes(); | |
} else { | |
var hourm = today.getHours() + ".0" + today.getMinutes(); | |
} | |
var time_int = parseInt(hourm, 10); | |
if (day != 0 && day != 6) { | |
display_1 = "Showroom hours today: 9AM - 6PM" | |
if (hourm <= 17 && hourm >= 9) { | |
display_2 = "Open now" | |
} else if (hourm > 17 && hourm <= 18) { | |
display_2 = "Closing soon" | |
} else { | |
display_2 = "Closed" | |
} | |
} else if (day == 0) { | |
display_1 = "Showroom hours today:"; | |
display_2 = "Closed"; | |
} else if (day == 6) { | |
display_1 = "Showroom hours today: 10AM - 5PM" | |
if (hourm <= 16 && hourm >= 10) { | |
display_2 = "Open now" | |
} else if (hourm > 16 && hourm <= 17) { | |
display_2 = "Closing soon" | |
} else { | |
display_2 = "Closed" | |
} | |
} | |
document.getElementById('display_1').innerHTML = display_1; | |
document.getElementById('display_2').innerHTML = "<strong>"+display_2+"</strong>"; | |
}; | |
</script> | |
<p><span id="display_1"></span><span id="display_2"></span></> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment