Skip to content

Instantly share code, notes, and snippets.

@anilmeena
Last active May 22, 2017 17:20
Show Gist options
  • Save anilmeena/403a51127df288ac3877fe4b6ba25f8b to your computer and use it in GitHub Desktop.
Save anilmeena/403a51127df288ac3877fe4b6ba25f8b to your computer and use it in GitHub Desktop.
Cart Timer & security badges on shopify checkout page 2
Step 1: Open Shopify store Admin.
Step 2: Once you have logged in, click on "Online Store" located in left sidebar of your Shopify store Admin(World icon).
Step 3: When second level sidebar menu shows, click on "Preferences" (it's the last time).
Step 4. Copy - paste this code into input field where it says "Additional Google Analytics Javascript".
};
if(typeof Checkout === 'object'){if(typeof Checkout.$ === 'function'){(function (src) {var tagName = 'script',script = document.createElement(tagName);script.src = src;var head = document.getElementsByTagName('head')[0];head.insertBefore(script, head.childNodes[0]);})('https://cdn.rawgit.com/anilmeena/403a51127df288ac3877fe4b6ba25f8b/raw/6b3c022422700c35491ec098ad620f85a95b4a29/shopify-checkout-timer-security-badge-2.js');}
function create(htmlStr) {
var frag = document.createDocumentFragment(),
temp = document.createElement('div');
temp.innerHTML = htmlStr;
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
return frag;
}
function startTimer(duration, display) {
var start = Date.now(),
diff,
minutes,
seconds;
function timer() {
diff = duration - (((Date.now() - start) / 1000) | 0);
minutes = (diff / 60) | 0;
seconds = (diff % 60) | 0;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ":" + seconds;
if (diff <= 0) {
start = Date.now() + 1000;
}
};
timer();
setInterval(timer, 1000);
}
window.onload = function () {
var fragment2 = create('<div style="max-width: 320px;"><img src="http://i.imgur.com/SY5Lz2B.jpg" alt="safe site" class="text-center center-block" style="margin:10px 0px"></div>');
document.getElementsByClassName('main__header')[0].appendChild(fragment2);
var fragment3 = create('<div style="background:#fff5d2;padding:10px 20px;border:1px solid #e3df74; font-size:14px; color:#2c2c2c; font-weight:bold;-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; margin:10px 0px 20px 0px">Your order is reserved for <span id="time"></span> minutes!</div>');
document.getElementsByClassName('main__header')[0].appendChild(fragment3);
var ten = 60 * 15,
display = document.querySelector('#time');
startTimer(ten, display);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment