async function setDateTimeInCart() { try { const response = await fetch('/cart/update.js', { method: "POST", headers: { 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/json' }, body: JSON.stringify({ attributes: { Discountly_dateTime:`${globalFields.Storetime()},${Shopify.shop}` } }) }); if (!response.ok) { throw new Error(`Error: ${response.statusText}`); } const data = await response.json(); // console.log('Cart updated successfully:', data); } catch (error) { // console.error('Failed to update cart:', error); } } // Add event listener for page load to update the cart attribute window.addEventListener('load', async () => { await setDateTimeInCart(); });