RPeraltaJr
10/14/2019 - 8:39 PM

Cookie/Privacy Policy pop up

setTimeout(function () {
    $("#cookieConsent").slideDown(); 
}, 3000); 

$("*[data-cookie-consent]").click(function(e) {
    e.preventDefault();
    $.ajax({
        type:'POST',
        url: siteSettings.theme + '/components/global/cookie-consent/cookie-consent.php',
        data: { cookieConsent: 'true' },
        success:function(response){
            $("#cookieConsent").slideUp();
            // console.log(response);
        }
    });
});
<?php 
    session_start();
    // unset($_SESSION['cookieConsent']); // clear session manually
    
    // destroy session if a certain amount of time has passed
    $inactivity = 1209600; // two weeks (in seconds)
    if (isset($_SESSION['cookieConsent']) && (time() - $_SESSION['cookieConsent'] > $inactivity)):
        session_destroy();   
        session_unset(); 
    endif;

    // Ajax post request (when user clicks OK button)
    if ( isset($_POST['cookieConsent']) ):
        $_SESSION['cookieConsent'] = time();
    endif;

    // Show pop up if a session has not been set
    if( !isset($_SESSION['cookieConsent']) ):
?>

<div id="cookieConsent" class="cookie-consent">
    <div class="container">
        <div class="col">
            <ul class="list-inline">
                <li><p>We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.</p></li>
                <li><button type="button" data-cookie-consent>OK</button></li>
                <li><a href="<?php echo home_url(); ?>/cookie-policy">COOKIE POLICY</a></li>
            </ul>
        </div>
    </div>
</div>

<?php endif; ?>