Caching code snippets
-
Hello
I have a problem with my code snippet who care about opening time.
In certain cases happen that the code not run correctly or not run at all. One think is interesting when i am logged in as admin everything works but when i logged out it looks like code is stuck or something like this but when i clear cache it looks good and code works correctly on user site too.
I am think if is possible somehow exclude this code from caching maybe this can help.
date_default_timezone_set(“Europe/Bratislava”);
$current_day = date(‘D’);
$current_time = date(‘H:i:s’, strtotime($current_time . ‘ + 2 hours’));// Set the opening hours for each day
$opening_hours = array(
‘Mon’ => array(‘open’ => ’11:00:00′, ‘close’ => ’22:00:00′),
‘Tue’ => array(‘open’ => ’11:00:00′, ‘close’ => ’22:00:00′),
‘Wed’ => array(‘open’ => ’11:00:00′, ‘close’ => ’22:00:00′),
‘Thu’ => array(‘open’ => ’11:00:00′, ‘close’ => ’22:00:00′),
‘Fri’ => array(‘open’ => ’11:00:00′, ‘close’ => ’16:00:00′),
‘Sat’ => array(‘open’ => ’13:00:00′, ‘close’ => ’22:00:00′),
‘Sun’ => array(‘open’ => ’13:00:00′, ‘close’ => ’21:00:00′)
);// Check if restaurant is open
if (isset($opening_hours[$current_day]) && $current_time >= $opening_hours[$current_day][‘open’] && $current_time <= $opening_hours[$current_day][‘close’]) { // restaurant is open, so do nothing } else { // restaurant is closed, hide add to cart button and display message add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’); add_action( ‘woocommerce_before_add_to_cart_button’, ‘cwpai_display_closed_message’, 25 ); } / // Function to display closed message / function cwpai_display_closed_message() { ?>
<?php
echo ‘Grange je práve zatvoreny. Objednajte si cez otváracie hodiny prosím.’;
}The page I need help with: [log in to see the link]
- The topic ‘Caching code snippets’ is closed to new replies.