Actually, I want to store the latest product URL in the cookie, so If the user clicks on the CONTINUE SHOPPING button on the cart page, it redirects to the last access product page. If the cookie has the value then the user redirects otherwise, it redirects to the SHOP page.
Here is the code, that I applied.
<script src="https://code.jquery.com/jquery-3.7.0.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js" type="text/javascript"></script>
<script type="text/javascript">
if (window.location.href.indexOf("products") > -1) {
var latestProductUrl = window. location.href;
$.cookie("lastProductUrl", latestProductUrl);
console.log('Success '+$.cookie("lastProductUrl"));
}
else if(window.location.href.indexOf("cart") > -1){
console.log('here:'+$.cookie("lastProductUrl"));
}
</script>
It shows me in the console. Success: defined and retrieved. Here: Undefined.