【问题标题】:How can i add Order Estimator to Shopify product details page如何将订单估算器添加到 Shopify 产品详细信息页面
【发布时间】:2021-12-12 02:26:47
【问题描述】:

基本上,我想显示 “免费送货 {delivery-estimate}。在 {time-counter} 内订购” 在我的 Shopify 页面上添加到购物车按钮上方。我该怎么做?

注意:

  1. 预计交货时间应在当前日期的 7 天之后。
  2. 时间计数器应在下午 1:00 刷新,如果时间在下午 1:00 之后,我想在估计日期上再增加一天。

这是我之前找到的,但我无法将其更改为我最初想要的格式。

<script language="JavaScript"> 
function day(a) {
    var date = new Date();
    var hours = date.getHours();

    // If after 3pm, add 1 day
    if(hours > 15) a++;

    var expectedDeliveryDate = addWeekdays(date, a);
    document.write(expectedDeliveryDate.toDateString() + ' with Standard Delivery');
}

function addWeekdays(fromDate, days) {
    var count = 0;
    while (count < days) {
        fromDate.setDate(fromDate.getDate() + 1);
        if (fromDate.getDay() != 0 && fromDate.getDay() != 6) // Skip weekends
            count++;
    }
    return fromDate;
}

</script>

<body>
<script language="JavaScript">
day(1)
</script>

【问题讨论】:

    标签: javascript shopify


    【解决方案1】:

    试试这样的,你可以根据你的需要过滤这个:

    const date = new Date()
    const hours = date.getHours()
    
    const newDate = new Date(date);
    const deliveryEstimate = hours < 13 ? new Date(newDate.setDate(newDate.getDate() + 7)) : new Date(newDate.setDate(newDate.getDate() + 8))
    const orderWithinValue = hours < 13 ? 13-hours : hours-13
    
    console.log(`FREE delivery by ${deliveryEstimate.toISOString().split('T')[0]}. Order within ${orderWithinValue} hours`)

    您的问题陈述将只有几个“如果条件”,您需要相应地处理它们。

    【讨论】:

    • 很高兴我能帮上忙
    猜你喜欢
    • 2014-08-16
    • 2016-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    相关资源
    最近更新 更多