//PRODUCT TIMERS // function productTimerCountDown() { var showholidaytimer = "no"; // Change this to "yes" or "no" as needed var bankholidaytext = "For bank holiday delivery timelines, please visit our special trading hours page here"; // Supplier data array with details for each supplier's message type, cutoff time, lead time, and more. var suppliersData = [ { Supplier: "Dynamic", SupplierCode: 2629, Cutoff: "4:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "Nautilus", SupplierCode: 2630, Cutoff: "4:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "Nautilus", SupplierCode: 1756, Cutoff: "4:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "Dams", SupplierCode: 1010, Cutoff: "2:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "Darwin", SupplierCode: 1476, Cutoff: "2:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "Lavoro", SupplierCode: 1813, Cutoff: "2:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "North West Teas", SupplierCode: 1107, Cutoff: "2:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "UFP", SupplierCode: 1190, Cutoff: "2:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "Dynamic", SupplierCode: 1074, Cutoff: "4:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "TC", SupplierCode: 1108, Cutoff: "4:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "Vow", SupplierCode: 1001, Cutoff: "4:30pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "CTS", SupplierCode: 1071, Cutoff: "5:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "Exertis", SupplierCode: 1013, Cutoff: "5:00pm", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "Silverline ND", SupplierCode: 1293, Cutoff: "11am", LeadTime: 1, MessageType: "Dynamic", StaticMessages: null, }, { Supplier: "Silverline", SupplierCode: 1008, Cutoff: "11:00am", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Albion", SupplierCode: 1755, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Teknik", SupplierCode: 1816, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Summit 1977", SupplierCode: 2512, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Hill Interiors", SupplierCode: 2038, Cutoff: "2:00pm", LeadTime: "3-5 working days", MessageType: "Static", StaticMessages: "Order before 2pm for delivery within 3-5 working days.
See further terms here.", }, { Supplier: "Fellowes", SupplierCode: 1014, Cutoff: "2:00pm", LeadTime: "3-5 working days", MessageType: "Static", StaticMessages: "Order before 2pm for delivery within 3-5 working days.
See further terms here.", }, { Supplier: "Mogo", SupplierCode: 2248, Cutoff: "2:00pm", LeadTime: "3-5 working days", MessageType: "Static", StaticMessages: "Order before 2pm for delivery within 3-5 working days.
See further terms here.", }, { Supplier: "Boss", SupplierCode: 1405, Cutoff: "4:00pm", LeadTime: "4-6 weeks", MessageType: "Static", StaticMessages: "Order before 4pm for delivery within 4-6 weeks.
See further terms here.", }, { Supplier: "OE Electrics", SupplierCode: 1812, Cutoff: "5:00pm", LeadTime: "7-10 working days", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 7-10 working days.
See further terms here.", }, { Supplier: "Allcam", SupplierCode: 2039, Cutoff: "2:00pm", LeadTime: "2 working days", MessageType: "Static", StaticMessages: "Order before 2pm for delivery within 2 working days.
See further terms here.", }, { Supplier: "Power Data Tech", SupplierCode: 2154, Cutoff: "2:00pm", LeadTime: "2 working days", MessageType: "Static", StaticMessages: "Order before 2pm for delivery within 2 working days.
See further terms here.", }, { Supplier: "Amp Wire", SupplierCode: 1746, Cutoff: "2:00pm", LeadTime: "5 working days", MessageType: "Static", StaticMessages: "Order before 2pm for delivery within 5 working days.
See further terms here.", }, { Supplier: "Zap", SupplierCode: 1761, Cutoff: "5:00pm", LeadTime: "5 working days", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 5 working days.
See further terms here.", }, { Supplier: "Tabilo", SupplierCode: 2124, Cutoff: "5:00pm", LeadTime: "5 working days", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 5 working days.
See further terms here.", }, { Supplier: "Silverline", SupplierCode: 1292, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Office interiors", SupplierCode: 1519, Cutoff: "5:00pm", LeadTime: "10 working days", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 10 working days.
See further terms here.", }, { Supplier: "Advanced", SupplierCode: 2112, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Screen Innovations", SupplierCode: 1927, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Pledge", SupplierCode: 1980, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Mobili", SupplierCode: 2126, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Gresham", SupplierCode: 2098, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Mint", SupplierCode: 2192, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Spaceright", SupplierCode: 1088, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, { Supplier: "Metalliform", SupplierCode: 1256, Cutoff: "5:00pm", LeadTime: "3-4 weeks", MessageType: "Static", StaticMessages: "Order before 5pm for delivery within 3-4 weeks.
See further terms here.", }, ]; // SVG icon var svgDeliveryInfoIcon = ``; // Content for the first div var staticDeliveryTimer = `

${svgDeliveryInfoIcon}Delivery Info

Delivery Details Loading
`; // Content for the first div var deliveryTimer = `

${svgDeliveryInfoIcon}Delivery Info

Delivery Details Loading
`; // Content for the second div var deliveryTimerTwo = `

${svgDeliveryInfoIcon}Delivery Info

Next day delivery optional if ordered by 3pm Subject to stock Check Stock
`; // Content for the third div var thirdDivContent = `
Call 0800 321 3651 for more Information
`; /* var buyinginbulk = `

Buying In Bulk?

Get a quote here
`;*/ // Append the banners to the target element on the product page jQuery(".desktop .productaddtocart_container .product ").after( // deliveryTimer + deliveryTimerTwo staticDeliveryTimer + deliveryTimer ); jQuery(".mobile .softgraybackground.product-shopping-actions").after( // deliveryTimer + deliveryTimerTwo .mobile .softgraybackground.product-shopping-actions staticDeliveryTimer + deliveryTimer ); /* jQuery(".productaddtocart_container ").append( // deliveryTimer + deliveryTimerTwo staticDeliveryTimer + deliveryTimer ); jQuery(".productgridwidget .softgraybackground").after( staticDeliveryTimer + deliveryTimer );*/ //move the product add to cart up when the selection is made /*$(".mobile .productaddtocart_container.mobile-widget-wrapper") .insertAfter(".mobile .product-summary .product-title-wrapper") .addClass("movedproductContainer");*/ /*$(".mobile .productaddtocart_container.mobile-widget-wrapper") .insertAfter(".mobile .product-summary .product-details-wrapper") .addClass("movedproductContainer");*/ $(".staticdelivery-details").hide(); $(".delivery-details").hide(); /* category timer change text $(".productaddtocart_container .product, .productgridwidget .product").each(*/ $( ".productaddtocart_container .product, .mobile .softgraybackground.product-shopping-actions " ).each(function () { const $this = $(this); let $statictarget; let $timertarget; // Find the top-level parent // Helper functions to toggle between static and timer delivery details function toggleStaticDeliveryDetails($element) { $element.find(".staticdelivery-details").show(); $element.find(".delivery-details").hide(); $element.parent().find(".staticdelivery-details").show(); $element.parent().find(".delivery-details").hide(); } function toggleTimerDeliveryDetails($element) { $element.find(".staticdelivery-details").hide(); $element.find(".delivery-details").show(); $element.parent().find(".staticdelivery-details").hide(); $element.parent().find(".delivery-details").show(); } // Determine the target elements for static and timer messages based on the page type (list or details) if ($this.hasClass("tileparent-list")) { $statictarget = $this.find(".staticdelivery-details .deliverytext"); $timertarget = $this.find(".delivery-details.timer .timertext"); console.log("list page"); } else { $statictarget = $this .parent() .find(".staticdelivery-details .deliverytext"); $timertarget = $this.parent().find(".delivery-details.timer .timertext"); console.log("details page"); } /*IF YES FOR HOLIDAYS */ // Handle holiday timer display if (showholidaytimer == "yes") { $statictarget.html(bankholidaytext); toggleStaticDeliveryDetails($this); $(".staticdelivery-details").hide(); $(".hours.openstatus").hide(); $(".askaquestion").hide(); $(".chatbtn").hide(); $(".imageaskaquestion").hide(); } else { // Loop through suppliers and update messages suppliersData.forEach(function (supplier) { // Skip this supplier if the MessageType is "hidden" if (supplier.MessageType === "HIDDEN") { return; // Move to the next supplier } if (supplier.MessageType === "Static") { // Assuming $this is a jQuery object representing the element you're working with // and $statictarget is the target element where you want to display the message. if ($this.hasClass(`supplier_${supplier.SupplierCode}`)) { $statictarget.html(`${supplier.StaticMessages}`); toggleStaticDeliveryDetails($this); } } }); /* DYNAMIC TIMERS */ // DYNAMIC TIMERS function timerFunction() { try { const now = new Date(); let deliveryDate = "Tomorrow"; // Default delivery date const today = now.getDay(); // Helper function to convert 12-hour time format to 24-hour format /* function convertTimeTo24Hour(time) { const [hour, period] = time.match(/(\d+)([ap]m)/).slice(1, 3); let hours = parseInt(hour); if (period === "pm" && hours < 12) hours += 12; // Adjust for PM if (period === "am" && hours === 12) hours = 0; // Adjust for AM return hours; } */ function convertTimeTo24Hour(time) { const [hourMin, period] = time.split(/(?=[ap]m)/i); let [hours, minutes] = hourMin.split(":"); hours = parseInt(hours); minutes = parseInt(minutes || "0"); if (period.toLowerCase() === "pm" && hours < 12) hours += 12; if (period.toLowerCase() === "am" && hours === 12) hours = 0; return { hours, minutes }; } function formatDate(date) { const day = String(date.getDate()).padStart(2, "0"); // Day with leading zero const month = date.toLocaleString("default", { month: "short" }); // Short month name const year = date.getFullYear(); // Full year return `${day} ${month} ${year}`; } // Process each supplier's dynamic delivery message suppliersData.forEach(function (supplier) { if (supplier.MessageType === "Dynamic") { const cutoff = supplier.Cutoff; const supplierCode = supplier.SupplierCode; let leadTime = supplier.LeadTime; // Check if the current product belongs to this supplier if ($this.hasClass(`supplier_${supplierCode}`)) { /* console.log(` Supplier: "${supplier.Supplier}", SupplierCode: ${supplier.SupplierCode}, Cutoff: "${supplier.Cutoff}", LeadTime: "${supplier.LeadTime}", MessageType: "${supplier.MessageType}", StaticMessages: "${supplier.StaticMessages}" `); */ // Get cutoff hour and compare it to the current time const { hours: cutoffHour, minutes: cutoffMinutes } = convertTimeTo24Hour(cutoff); let cutoffDate = new Date(now); cutoffDate.setHours(cutoffHour, cutoffMinutes, 0, 0); // Set cutoff time for today // Adjust lead time if the current time has passed the cutoff // Adjust the cutoffDate if the current time has passed the cutoff if (now > cutoffDate) { if (today === 6 || today === 0) { //dont add lead time when on weekend if cutoff time passed } else { leadTime += 1; // Increment lead time if cutoff has passed cutoffDate.setDate(cutoffDate.getDate() + 1); // Move cutoff date to the next day console.log("Cutoff passed, updated LeadTime:", leadTime); console.log( "Cutoff passed, updated cutoffDate:", cutoffDate ); } } // Skip weekends for displayCutoffDate if (cutoffDate.getDay() === 6) { cutoffDate.setDate(cutoffDate.getDate() + 2); // Skip to Monday if it's Saturday } else if (cutoffDate.getDay() === 0) { cutoffDate.setDate(cutoffDate.getDate() + 1); // Skip to Monday if it's Sunday } // Calculate the cutoff date to display // let displayCutoffDate = `${cutoffDate.toDateString()} by ${cutoff}`; let displayCutoffDate = `${formatDate( cutoffDate )} by ${cutoff}`; // Calculate the estimated delivery date, skipping weekends // Helper function to get the next weekday after a specified lead time, avoiding weekends function getNextWeekday(date, leadTime) { let nextDate = new Date(date); // If it's Saturday or Sunday, start from Monday if (nextDate.getDay() === 6) { // Saturday nextDate.setDate(nextDate.getDate() + 2); } else if (nextDate.getDay() === 0) { // Sunday nextDate.setDate(nextDate.getDate() + 1); } let daysAdded = 0; // Continue adding days while ensuring they are weekdays while (daysAdded < leadTime) { nextDate.setDate(nextDate.getDate() + 1); // Check if it's a weekday if (nextDate.getDay() !== 6 && nextDate.getDay() !== 0) { daysAdded++; } } return nextDate; } // Main script where you calculate estimated delivery date const estimatedDeliveryDate = getNextWeekday(now, leadTime); // deliveryDate = estimatedDeliveryDate.toDateString(); deliveryDate = formatDate(estimatedDeliveryDate); console.log("Final Delivery Date:", deliveryDate); // Calculate remaining time until the cutoff const remain = (cutoffDate - now) / 1000; // Calculate remaining seconds const hh = Math.floor((remain / 3600) % 24); // Calculate remaining hours const mm = Math.floor((remain / 60) % 60); // Calculate remaining minutes // Generate the timer message based on remaining time and current day let timerText; if (today === 6 || today === 0) { // For weekends timerText = `Weekend Orders before ${displayCutoffDate} for earliest delivery by ${deliveryDate}
Applicable to in-stock items only. * See Exceptions`; } else { timerText = `Order within ${hh}h ${mm}m for earliest delivery by ${deliveryDate}
Applicable to in-stock items only. * See Exceptions`; } // Display the timer text and update visibility for dynamic details $timertarget.html(timerText); toggleTimerDeliveryDetails($this); // Show timer details } } }); } catch (error) { console.error("Error in timerFunction:", error); } } // Initial call timerFunction(); // Set an interval to check every minute setInterval(function () { timerFunction(); }, 60000); } }); /* toggle closed / open for contact page */ function toggleOpenStatus($element) { const now = new Date(); const currentHour = now.getHours(); const openHour = 9; const closeHour = 17; if (currentHour >= openHour && currentHour < closeHour) { $element.find(".hours.openstatus").show(); $element.find(".closed.openstatus").hide(); $element.parent().find(".hours.openstatus").show(); $element.parent().find(".closed.openstatus").hide(); } else { $element.find(".hours.openstatus").hide(); $element.find(".closed.openstatus").show(); $element.parent().find(".hours.openstatus").hide(); $element.parent().find(".closed.openstatus").show(); } } // Initial call toggleOpenStatus($(document)); // Set an interval to check every minute setInterval(function () { toggleOpenStatus($(document)); }, 60000); }