Support

Account

Home Forums Front-end Issues Bizzare Caching Behavior

Unread

Bizzare Caching Behavior

  • I have a text field called ‘duedate’ that I just added to the product pages. It seems to be interfering with a PHP countdown which I wrote for users to see when a delivery will arrive (ie. Order within 2 hours 5 minutes, get it tomorrow.)

    By interfering I mean that when ‘duedate’ is specified, my PHP countdown it doesn’t update on the front end – the countdown stays the same (unlike product pages with ‘duedate’ not filled) and it and doesn’t respond to edits to the PHP countdown, UNLESS I change the text of the field or remove it.

    It’s almost like it goes into a cached state but only when that field has something in it…

    Things I’ve tried:
    Changing the name of the field (not the label)
    Removing my requests to the field from the product page template

    I’m super puzzled…

    My countdown PHP (I know it’s not written very well but I can’t see how it would cause this):

    
    if (! get_field("delivery_tomorrow")){
    date_default_timezone_set("Europe/London");
    $currentdate = time();
    $deadlinepassed = false;
    $weekDay = date('w', strtotime('+1 day',$currentdate));
    $date = strtotime("2PM");
    $remaining = $date - time();
    $day = "Tomorrow";
    
    if (date('H:i') >= date('H:i', $date)){
        $deadlinepassed = true;
        $weekDay = date('w', strtotime('+2 day',$currentdate));
        $actualremaining = $remaining + 86400;
    } else {
        $deadlinepassed = false;
        $weekDay = date('w', strtotime('+1 day',$currentdate));
        $actualremaining = $date - time();
    }
    
    if(($weekDay == 2)) //Check if the day is saturday or not.
        $tomorrow="Tuesday";
    else if (($weekDay == 3))
        $tomorrow="Wednesday";
    else if (($weekDay == 4))
        $tomorrow="Thursday";
    else if (($weekDay == 5))
        $tomorrow="Friday";
        
    if ($deadlinepassed){
        $day = $tomorrow;
    }
    
    $hoursremaining = floor($actualremaining / 3600);
    $minutesremaining = floor(($actualremaining / 60));
    $actualminutes = ($minutesremaining - ($hoursremaining *60));
    
    if(date('D') == 'Sat' || date('D') == 'Sun' || date('D') == 'Fri' || ($hoursremaining < 0 && $actualminutes < 0) || (date('D') == 'Thu') && $deadlinepassed) {
      $html="";
    } else {
      $html  ='<div class="getit"><span class="titleprimary">Get it</span><span class="titlesecondary"> ' .$day. '</span><span class="country"> (UK)-</span><br>';
      $html .='<span class="descprimary">Order within </span><span class="hoursleft">' .$hoursremaining. ' hours</span><span class="minutesleft"> ' .$actualminutes. ' minutes</span><span class="descprimary"> and get it on </span><span class="arrivalday">' .$tomorrow. '</span></div><br>';
    }
    
    if ($hoursremaining <= 0){
    	$html .='<style>.hoursleft{display:none;}</style>';
    }
    
    $y = $product->get_title(); 
    
    if (((strpos($y, 'Used') !== false) || (strpos($y, 'Preowned')))){
        $html .='<style>.getit{display:none;}</style>';
    }
    
    echo $html;
    }
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.