Last active
May 9, 2023 22:53
-
-
Save anilmeena/eaa5e07a69c5486a1d007e6e06f1f197 to your computer and use it in GitHub Desktop.
Cart Timer on shopify checkout page
This file contains 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/eaa5e07a69c5486a1d007e6e06f1f197/raw/bf8c8dc50f717c1c59bc9027e9aada2fab3cff7d/shopify-cart-timer-checkout.js');} |
This file contains 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 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
After i have paste the link, then I will save and that is all right