I want to show and hide div based on day and time. I have not much experience with PHP, but I think I found a code for this. But I don't know how to sort and how the codes shall be set up.
I want it to show like this during opening hours: http://boxmedia.no (bottom of frontpage).
It's a form with one field and one button. It's in Norwegian and says: Fill in your number here. And press here, then we call you back in 10 mins
This is the code for the form:
<div class="container"> <div class="row-centered main-btn ring_me">
<?php
echo do_shortcode('[contact-form-7 id="249" title="Untitled"]');
?> </div> <!--div class="row-centered sec-btn" style="display:none;">
<span><input max-size="30" type="text" id="contact_no" name="contact_no"/>
</span><span class="btn btn-success btn-lg">
<font><font class="goog-text-highlight">
<a href="<?php echo home_url();
?>/kontakt-oss">Send </a> </font></font> </span></div--> </div>
And this is the code I think will make it show during opening hours: 8am to 4pm. And not in weekends.
But where do I put this in the existing code above:
<?php date_default_timezone_set('Europe/Oslo');
$currentHour = date("H");
$openTime = 8;
$closeTime = 16;
if ($currentHour >= $openTime && $currentHour < $closeTime){
$css = 'display:block;';
}else{
$css = 'display:none;';
}
echo '<style type="text/css">.timeBasedLink {'.$css.'}</style>'; ?>
if (date("w") == 0 || date("w") == 6 || $currentHour < $openTime ||
$currentHour >= $closeTime)
{
$css = 'display:none;';
}
else
{
$css = 'display:block;';
}
--------------- Added February 2. 2015 ---------------
And is this the code to add to my css file? And is it placed correctly? Is the class .TimeOn ? How I can connect the TimeOn to ring_me or what the class is called?
.ring_me input[type="tel"] {
width: 258px;
margin-right: 20px;
.timeOn {
display:block;
}
.timeOff {
display:none;
}
}
And this is another place in the CSS:
.ring_me input[type="tel"] {
.timeOn {
display:block;
}
.timeOff {
display:none;
}
font-size: 20px;
line-height: 24px;