-
Notifications
You must be signed in to change notification settings - Fork 0
/
shipping-countdown-timer.php
105 lines (88 loc) · 2.72 KB
/
shipping-countdown-timer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function shipping_countdown_timer($attributes)
{
$attr = shortcode_atts( array(
'hour' => 16,
'minute' => 0,
'second' => 0
), $attributes );
?>
<style>
@media (min-width:500px){
p.Days{
color: #000000;
font-family: "Arial";
font-weight: normal;
font-style: normal;
text-align: center;
font-size: 20px;
margin-top: 1%;
border-style: dotted;
width: 30%;
margin-left: 35%;
}
}
@media (max-width:500px){
p.Days{
color: #000000;
font-family: "Arial";
font-weight: normal;
font-style: normal;
text-align: center;
font-size: 20px;
margin-top: 1%;
border-style: dotted;
}
}
div.allCount{
border-style: ridge;
border-width: thin;
}
h2.headDays{
color: #000000;
font-family: "Arial";
text-align: center;
font-weight: 700;
}
</style>
<?php
$content = "<div class='allCount'>";
$content .= "<h2 class='headDays'>Next Shipping</h2>";
$content .= "<p class='Days' id='showDays'></p></div>";
?>
<script>
//code is based on 24 hour-clock system
//shipping time is chosen as 16:00 for days monday-tuesday-wednesday-thursday-friday
//it is restricted such that there will be no shipping on saturday and sunday
var x = setInterval(function()
{
var givenHour = <?php echo $attr[hour] ?>;
var givenMinute = <?php echo $attr[minute] ?>;
var givenSecond = <?php echo $attr[second] ?>;
var deliverDays = 0;
var date = new Date();
var day = date.getDay();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
//remaining days are calculating if it is weekend (friday or/and saturday is adding)
if((day == 5 && hour >= givenHour ) || (day == 6 && hour < givenHour)) deliverDays = 2;
else if((day === 6 && hour >= givenHour ) || (day == 0 && hour < givenHour)) deliverDays = 1;
//remaining time is calculating
var remainingHour = givenHour - hour - 1;
var remainingMinute = givenMinute - minute;
var remainingSecond = givenSecond - second - 1;
if(remainingHour < 0 ) remainingHour += 24;
if(remainingMinute < 0 ) remainingMinute += 60;
if(remainingSecond < 0 ) remainingSecond += 60;
if(givenHour == hour && givenMinute >= minute ) { remainingHour = 0; }
if(givenMinute == minute) remainingMinute = 0;
var show0 = remainingHour + " Hours " + remainingMinute + " Minutes " + remainingSecond + " Seconds ";
var show1 = deliverDays + " Days " + remainingHour + " Hours " + remainingMinute + " Minutes " + remainingSecond + " Seconds ";
if(deliverDays > 0) document.getElementById("showDays").innerHTML = show1;
else document.getElementById("showDays").innerHTML = show0;
}, 1000);
</script>
<?php
return $content;
}
add_shortcode( 'shipping-countdown-timer', 'shipping_countdown_timer' );