Advertisement
Guest User

bcp_eligable_twoday

a guest
Nov 15th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var allthesky = [];
  2. var state_name;
  3. var bcp_eligable;
  4. function myFunction() {
  5.     setTimeout(function(){ checkCookie(); }, 2000);
  6. }
  7.   //call the function
  8.   myFunction();
  9.   //End call
  10. function setCookie(cname,cvalue) {
  11.  
  12.   var now = new Date();
  13.   now.setTime(now.getTime() + 4 * 3600 * 1000);
  14.   var expires = "expires=" + now.toUTCString();
  15.   document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  16. }
  17. function getCookie(cname) {
  18.     var name = cname + "=";
  19.     var decodedCookie = decodeURIComponent(document.cookie);
  20.     var ca = decodedCookie.split(';');
  21.     for(var i = 0; i < ca.length; i++) {
  22.         var c = ca[i];
  23.         while (c.charAt(0) == ' ') {
  24.             c = c.substring(1);
  25.         }
  26.         if (c.indexOf(name) == 0) {
  27.             return c.substring(name.length, c.length);
  28.         }
  29.     }
  30.     return "";
  31. }
  32. function threeday(){
  33.   $(".merge-two").css("display", "none");$(".merge-three").css("display", "block");
  34. }
  35. function twoday(){
  36.   $(".merge-two").css("display", "block");$(".merge-three").css("display", "none");
  37. }
  38.  
  39. function checkCookie() {
  40.  
  41.     {% for tag in product.tags %}
  42.     {% if tag contains 'bcp2day_eligible' %}
  43.       {% assign bcpeligible = tag | split: ":" %}
  44.         bcp_eligable = {{bcpeligible[1]}};
  45.     {% endif %}
  46.     {% if tag contains 'SKY' %}
  47.      {% assign new_tagg = tag %}
  48.         allthesky.push('{{new_tagg}}');
  49.     {% endif %}
  50.     {% endfor %}
  51.     if(bcp_eligable == false){
  52.       threeday();
  53.     }else{                
  54.       state_name = getCookie("two_day_state");
  55.       if (state_name != "") {
  56.         var sky = '{{product.variants.first.sku}}';
  57.           variant(sky);
  58.       } else {  
  59.           function callback(json){
  60.               state_name = json.state;
  61.               setCookie("two_day_state", state_name);
  62.               var sky = '{{product.variants.first.sku}}';
  63.               variant(sky);
  64.             }
  65.            $.ajax({
  66.               url: "https://geoip-db.com/jsonp",
  67.               jsonpCallback: "callback",
  68.               dataType: "jsonp",
  69.               success: function( location ) {
  70.                 state_name = location.state;
  71.                 setCookie("two_day_state", state_name);
  72.                 var sky = '{{product.variants.first.sku}}';
  73.                 variant(sky);
  74.               }
  75.           });
  76.       }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement