我正在修改插件“ Do It Simple Recurring Bookings”,以允许我通过在结帐时将预订重复一定次数来创建多个重复预订。
到目前为止,它的运行效果非常好...但是所有订单都在一个订单上。我需要将每个订单分开订购,以使供应商能够完成他们需要做的事情。
所以...我如何获取与预订重复的代码,以创建新订单并将新预订分配给新订单!?
我知道这与代码的最后一部分有关,我
我认为问题出在哪里。
public function dis_wcb_ro_rb_payment_complete( $order_id ) {
//check for reoccurring products
$dis_ro_order = new WC_Order( $order_id );
$dis_ro_items = $dis_ro_order->get_items();
$booking= new WC_Booking_Data_Store($order_id);
//now loop through the items searching for those that match Reoccurring Products
foreach ($dis_ro_items as $var => $dis_ro_item) {
$recurring_yes = get_post_meta($dis_ro_item['product_id'], '_dis_recurring_checkbox');
if($recurring_yes) {
//now loop through an reoccurring bookiong product
// get all parent ids of all bookings
$booking_ids =$booking->get_booking_ids_from_order_item_id( $var );
foreach($booking_ids as $booking_id) {
//need to get the meta data containing weeks (this is a dirty solution because the function 'wc_get_order_item_meta' should have a second parameter)
$get_meta_weeks = wc_get_order_item_meta($var, 'Repeating');
//now get what intervals were set by Admin/site owner
if(get_option('dis_wc_ro_month_field' == 'yes')){
$length = 'month';
}
if(get_option('dis_wc_ro_week_field' == 'yes')){
$length = 'week';
}
// get first booking details
$prev_booking = new WC_Booking( $booking_id );
// Don't want follow ups for follow ups
if ( $prev_booking->parent_id <= 0 ) {
//need to loop through booking based on number of weeks selected
// Did the previous booking have persons?
//what if they didn't
$persons = $prev_booking->get_persons();
for ($class_length = 1; $class_length <= ($get_meta_weeks-1); $class_length++) {
//need to decide if person option is needed then check if it exisits before useing
//different loop for month or week
if(get_option('dis_wc_ro_week_field') == 'yes'){
$new_booking = create_wc_booking(
$prev_booking->product_id, // Creating a booking for the previous bookings product
$new_booking_data = array(
'start_date' => strtotime( '+'.$class_length.' week', $prev_booking->start ), // same time, 1 week on
'end_date' => strtotime( '+'.$class_length.' week', $prev_booking->end ), // same time, 1 week on
'resource_id' => $prev_booking->resource_id, // same resource
//'product_id' => $booking_id,
//what to do if there are no persons?
'persons' => $persons
),
$prev_booking->get_status(), // Match previous bookings status
false // Not exact, look for a slot
);
**// parent_id does not seem to exist any longer so do it by meta
if($new_booking) {
$id = $new_booking->get_id();
update_post_meta($id, '_booking_parent_id', $booking_id);
//now update the post parent which is the order number
wp_update_post(array('ID' => $id, 'post_parent' => $order_id));**
}
}