Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var allthesky = [];
- var state_name;
- var bcp_eligable ;
- function myFunction() {
- setTimeout(function(){ checkCookie(); }, 2000);
- }
- //call the function
- myFunction();
- //End call
- function setCookie(cname,cvalue) {
- var now = new Date();
- now.setTime(now.getTime() + 4 * 3600 * 1000);
- var expires = "expires=" + now.toUTCString();
- document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
- }
- 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 "";
- }
- function checkCookie() {
- {% for tag in product.tags %}
- {% if tag contains 'bcp2day_eligible' %}
- {% assign bcpeligible = tag | split: ":" %}
- bcp_eligable = {{bcpeligible[1]}};
- {% endif %}
- {% if tag contains 'SKY' %}
- {% assign new_tagg = tag %}
- allthesky.push('{{new_tagg}}');
- {% endif %}
- {% endfor %}
- state_name = getCookie("two_day_state");
- if (state_name != "") {
- console.log("state_name",state_name);
- var sky = '{{product.variants.first.sku}}';
- variant(sky);
- } else {
- console.log("ajax api");
- function callback (json){
- console.log("ajax api callback")
- state_name = json.state;
- setCookie("two_day_state", state_name);
- var sky = '{{product.variants.first.sku}}';
- variant(sky);
- }
- $.ajax({
- url: "https://geoip-db.com/jsonp",
- jsonpCallback: "callback",
- dataType: "jsonp",
- success: function( location ) {
- state_name = location.state;
- setCookie("two_day_state", state_name);
- var sky = '{{product.variants.first.sku}}';
- variant(sky);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement