首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在产品页面中添加到购物车表单后显示估计调度日期

在产品页面中添加到购物车表单后显示估计调度日期
EN

Stack Overflow用户
提问于 2020-10-12 04:15:57
回答 1查看 166关注 0票数 3

我有一家Woocommerce商店,我想给我的客户看一个估计的发货日期,在add to cart表单下面。逻辑是

  1. 如果客户在下午12点之前下订单,它将在3-5个工作日内发出。
  2. 如果客户在下午12点后下订单,该订单将在4-5个工作日内发出。
  3. 如果客户在周末下订单,它应自动将其视为从星期一起的3-5个工作日。

我尝试了商人守则,但是我的逻辑有点复杂,所以我无法让它工作!

任何帮助都是非常感谢的!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-12 10:35:42

检查下面的代码(测试并运行良好)。如果您对不正确的时间有问题,请查看时区设置是否正确。根据您的查询,我假设时区应该是Kolkatta

Goto仪表板->设置->通用->时区

代码语言:javascript
运行
复制
function dispatch_message(){

    $current_time = current_time('D | H');
    $current_time = explode('|', $current_time );
    $current_day = isset( $current_time[0] ) ? trim( $current_time[0] ) : false;
    $current_hour = isset( $current_time[1] ) ? trim( $current_time[1] ) : false;
  
    $message = '4-5 Working Days.';
    
    if( in_array( $current_day, array( 'Fri', 'Sat', 'Sun' ) ) ){
        //Weekend
        $message = '3-5 Working Days from Monday.';

    }else if( $current_hour <= "12"){
        //Before 12pm IST
        $message = '3-5 Working Days.';
    }

    ?>
    <div style="clear: both"></div>
    <div style="margin-top: 10px;font-size: 17px;color: red;">
        <b>Est Dispatch Date:</b> <?php echo $message; ?>
    </div>
    <br>
    <?php
}
add_action( 'woocommerce_before_add_to_cart_button', 'dispatch_message' ); 

更新

您可以对上述代码进行更改,以隐藏某些类别的分派日期。添加if条件作为第一行代码,如下所示,然后返回,以跳过函数的其余部分。

代码语言:javascript
运行
复制
function dispatch_message(){

    if ( is_product() && has_term( array( 'dress', 'clothing' ), 'product_cat' ) ){
        return;
    }
    
    $current_time = current_time('D | H');
    $current_time = explode('|', $current_time );
    $current_day = isset( $current_time[0] ) ? trim( $current_time[0] ) : false;
    $current_hour = isset( $current_time[1] ) ? trim( $current_time[1] ) : false;

    $message = '4-5 Working Days.';

    if( in_array( $current_day, array( 'Fri', 'Sat', 'Sun' ) ) ){
        //Weekend
        $message = '3-5 Working Days from Monday.';

    }else if( $current_hour <= "12"){
        //Before 12pm IST
        $message = '3-5 Working Days.';
    }

    ?>
    <div style="clear: both"></div>
    <div style="margin-top: 10px;font-size: 17px;color: red;">
        <b>Est Dispatch Date:</b> <?php echo $message; ?>
    </div>
    <br>
    <?php
}
add_action( 'woocommerce_before_add_to_cart_button', 'dispatch_message' );
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64311606

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档