How to add cookies for popup in cart and checkout page

<?php if (is_cart() || is_checkout()) { ?> 

<script src="https://sitename.com/jquery.exitintent.js"></script>
<script src="https://sitename.com/jquerysession.js"></script>
<script type="text/javascript"> 

function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

var username = getCookie("cname");
if (username == "kook") {

}else{

jQuery(function() {
jQuery.exitIntent('enable');

jQuery(document).bind('exitintent', function() {
jQuery("#warning").slideDown();
});
jQuery("#warning a").bind('click', function(){
var now = new Date();
var time = now.getTime();
time += 3600 * 1000;
now.setTime(time);
document.cookie = 
'cname=' + 'kook' + 
'; expires=' + now.toUTCString() + '; path=/';
jQuery("#warning").slideUp();
location.reload();


});

});
} 
</script>
<?php }else{


}?>

Leave a Reply

Your email address will not be published. Required fields are marked *