Personalized checkout and custom promotions with Shopify Scripts
Hi everyone, 😀
I’ve been troubleshooting an issue where the “Not Secure” warning sometimes appears on our mobile site. This has only recently started happening and seems to coincide with our Add to Cart (ATC) button freezing up — preventing any further interaction on the page after hitting ATC.
Everything on our domain looks normal, but I suspect the issue may stem from this shipping date calculator code (see below). I’m also wondering if this code is optimised. Could it be contributing to the “Not Secure” error and freezing the ATC button?
Here’s the script:
<script>
document.addEventListener("DOMContentLoaded", function() {
try {
var today = new Date();
var options = { timeZone: 'Australia/Sydney', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false };
var timeString = today.toLocaleTimeString('en-AU', options);
var hour = parseInt(timeString.split(':')[0], 10);
var day = today.getDay();
var nextShippingDay = new Date(today);
var shippingText = "Ships by ";
if (hour >= 12) {
if (day >= 1 && day <= 4) {
nextShippingDay.setDate(today.getDate() + 1);
} else if (day === 5) {
nextShippingDay.setDate(today.getDate() + 3);
} else if (day === 6) {
nextShippingDay.setDate(today.getDate() + 2);
} else {
nextShippingDay.setDate(today.getDate() + 1);
}
} else {
shippingText = "Ships today, ";
}
// Format the date to a readable string
var dateOptions = { weekday: 'short', month: 'long', day: 'numeric', timeZone: "Australia/Sydney" };
var formattedDate = nextShippingDay.toLocaleDateString('en-AU', dateOptions);
document.getElementById('shipping-date').innerHTML = '<span class="shipping-text">' + shippingText + '</span><span class="shipping-date">' + formattedDate + '</span>';
} catch (error) {
document.getElementById('shipping-date').innerHTML = '<span class="shipping-text">Invalid Date</span>';
}
});
</script>
Any insights would be much appreciated. Thanks in advance!
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024