B
B
blackbb2016-03-24 12:16:22
PHP
blackbb, 2016-03-24 12:16:22

How to make a link change depending on the time?

There is a pizzeria store on wp with payment on the site. It is necessary to make it so that the user cannot order and pay on the site after 21-00 and before 10-00 in the morning, since the store is not working, and users are waiting for the order. The idea is to change the link of the "ORDER" button under the product. So that she, at the appointed time, throws it on the page, where there are explanations that the store does not accept orders at night. Tell me how to organize this in WP, maybe there are ready-made solutions, I haven’t found it yet. Can use functions or even javascript in general.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander N++, 2016-03-24
@blackbb

In theme functions.php

fucnction lockOrderUrl($url,$lockUrl = '#'){
$hour = date('H');
$lockLink = ($hour >=21 || $hour <=10 );
return $lockLink ? $lockUrl : $url;
}

In templates on the order button
<a href="<?=lockOrderUrl('Тут путь к заказу', 'линк куда нужно перекидывать можно зашить в функцию если он не меняется'); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question