在 WooCommerce 预订和约会中添加 2 个每周额外约会
Add 2 weekly additional appointments in WooCommerce Bookings And Appointments
我对 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() ), // same time, 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', $prev_appointment->get_start() ), // same time, 1 week on
'end_date' => strtotime( '+1 week', $prev_appointment->get_end() ), // same time, 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
);
}
}
但是我需要在第一个之后一周再创建一个。欢迎任何帮助。
要在 2 周后进行第二次额外预约,您可以尝试使用以下方法:
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' ), // same time, 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' ), // same time, 2 weeks on
'end_date' => strtotime( $prev_appointment->get_end() . '+ 2 weeks' ), // same time, 2 weeks 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_2['all_day'] = true;
}
create_wc_appointment(
$prev_appointment->get_product_id(), // Creating a appointment for the previous appointments product
$$new_appointment_data_2, // Use the data pulled above
$prev_appointment->get_status(), // Match previous appointments status
false // Not exact, look for next available slot
);
}
}
代码进入活动子主题(或活动主题)的 functions.php 文件。它应该有效。
我对 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() ), // same time, 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', $prev_appointment->get_start() ), // same time, 1 week on
'end_date' => strtotime( '+1 week', $prev_appointment->get_end() ), // same time, 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
);
}
}
但是我需要在第一个之后一周再创建一个。欢迎任何帮助。
要在 2 周后进行第二次额外预约,您可以尝试使用以下方法:
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' ), // same time, 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' ), // same time, 2 weeks on
'end_date' => strtotime( $prev_appointment->get_end() . '+ 2 weeks' ), // same time, 2 weeks 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_2['all_day'] = true;
}
create_wc_appointment(
$prev_appointment->get_product_id(), // Creating a appointment for the previous appointments product
$$new_appointment_data_2, // Use the data pulled above
$prev_appointment->get_status(), // Match previous appointments status
false // Not exact, look for next available slot
);
}
}
代码进入活动子主题(或活动主题)的 functions.php 文件。它应该有效。