微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在WooCommerce预订和约会中增加2个每周的附加约会

如何解决在WooCommerce预订和约会中增加2个每周的附加约会

我已经对WooCommerce预订和约会插件进行了自定义,因此当客户预订特定日期时,该插件会在第一个约会之后一周自动添加第二个约会。现在,我需要删除代码以在客户进行第一次约会时彼此之间每周注册三个约会。

当客户在11月9日星期一预订约会时,此消息在11月16日星期一登记了后续约会。

    // Set the follow up data
    $new_appointment_data = array(
        'start_date' => strtotime( '+1 week',$prev_appointment->get_start() ),// same time,1 week on
        'end_date'   => strtotime( '+1 week',$prev_appointment->get_end() ),1 week on
        'staff_ids'  => $prev_appointment->get_staff_ids(),// same staff
        'parent_id'  => $appointment_id,// set the parent
    );

现在,我不知道如何增加第三周的时间。这将是11月23日星期一的约会。


修改

这是我用来另外预约的代码片段:

add_action( 'woocommerce_appointment_in-cart_to_paid','auto_create_followup_appointment' );
add_action( 'woocommerce_appointment_unpaid_to_paid','auto_create_followup_appointment' );
add_action( 'woocommerce_appointment_confirmed_to_paid','auto_create_followup_appointment' );
function auto_create_followup_appointment( $appointment_id ) {
    // Get the prevIoUs appointment from the ID
    $prev_appointment = get_wc_appointment( $appointment_id );
    
    // Don't want follow ups for follow ups
    if ( $prev_appointment->get_parent_id() <= 0 ) {
        // Set the follow up data
        $new_appointment_data = array(
            'start_date' => strtotime( '+1 week',1 week on
            'end_date'   => strtotime( '+1 week',1 week on
            'staff_ids'  => $prev_appointment->get_staff_ids(),// same staff
            'parent_id'  => $appointment_id,// set the parent
        );
        // Was the prevIoUs appointment all day?
        if ( $prev_appointment->is_all_day() ) {
            $new_appointment_data['all_day'] = true;
        }
        create_wc_appointment( 
            $prev_appointment->get_product_id(),// Creating a appointment for the prevIoUs appointments product
            $new_appointment_data,// Use the data pulled above
            $prev_appointment->get_status(),// Match prevIoUs appointments status
            false                                // Not exact,look for next available slot
        );
    }
}

但是我需要在第一个之后每周创建另一个。欢迎任何帮助。

解决方法

要再隔两周进行第二次约会,可以尝试使用以下命令:

add_action( 'woocommerce_appointment_in-cart_to_paid','auto_create_followup_appointment' );
add_action( 'woocommerce_appointment_unpaid_to_paid','auto_create_followup_appointment' );
add_action( 'woocommerce_appointment_confirmed_to_paid','auto_create_followup_appointment' );
function auto_create_followup_appointment( $appointment_id ) {
    // Get the previous appointment from the ID
    $prev_appointment = get_wc_appointment( $appointment_id );
    
    // Don't want follow ups for follow ups
    if ( $prev_appointment->get_parent_id() <= 0 ) {
        // 1. First additional apointment (+1 week) - Set the follow up data
        $new_appointment_data_1 = array(
            'start_date' => strtotime( $prev_appointment->get_start() . '+ 1 week' ),// same time,1 week on
            'end_date'   => strtotime( $prev_appointment->get_end() . '+ 1 week' ),1 week on
            'staff_ids'  => $prev_appointment->get_staff_ids(),// same staff
            'parent_id'  => $appointment_id,// set the parent
        );
        // Was the previous appointment all day?
        if ( $prev_appointment->is_all_day() ) {
            $new_appointment_data_1['all_day'] = true;
        }
        create_wc_appointment( 
            $prev_appointment->get_product_id(),// Creating a appointment for the previous appointments product
            $new_appointment_data_1,// Use the data pulled above
            $prev_appointment->get_status(),// Match previous appointments status
            false                                // Not exact,look for next available slot
        );
        
        // 2. Second additional apointment (+2 weeks) - Set the follow up data
        $new_appointment_data_2 = array(
            'start_date' => strtotime( $prev_appointment->get_start() . '+ 2 weeks' ),2 weeks on
            'end_date'   => strtotime( $prev_appointment->get_end() . '+ 2 weeks' ),2 weeks on
            'staff_ids'  => $prev_appointment->get_staff_ids(),// set the parent
        );
        // Was the previous appointment all day?
        if ( $prev_appointment->is_all_day() ) {
            $new_appointment_data_2['all_day'] = true;
        }
        create_wc_appointment( 
            $prev_appointment->get_product_id(),// Creating a appointment for the previous appointments product
            $$new_appointment_data_2,look for next available slot
        );
    }
}

代码进入活动子主题(或活动主题)的functions.php文件中。应该可以。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?