Last active
May 10, 2017 08:21
-
-
Save anilmeena/a987697bfb81ca180359340f4ff4e6de to your computer and use it in GitHub Desktop.
Cart Timer & security badges on shopify checkout page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/a987697bfb81ca180359340f4ff4e6de/raw/6cea1c1a3ee7bff893f53746a9c851644ac0a121/shopify-checkout-timer-security-badge.js');} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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 fragment2 = create('<img src="http://i.imgur.com/b5SOV9x.jpg" alt="safe site" class="text-center center-block" style="margin:29px 0px">'); | |
document.getElementsByClassName('main__header')[0].appendChild(fragment2); | |
var ten = 60 * 10, | |
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