isset( $_POST[ $key ] ) ? sanitize_text_field( wp_unslash( $_POST[ $key ] ) ) : $default;
$start_time = $post_val( 'start_time' );
$end_time = $post_val( 'end_time' );
$rent_rule = $post_val( 'rent_rule' );
$location = $post_val( 'location' );
$date_info = ABPRF_Function::get_date_time_difference( $start_time, $end_time, $rent_rule );
$abprf_infos['post_id'] = $post_id;
$abprf_infos['start_time'] = $start_time;
$abprf_infos['end_time'] = $end_time;
$abprf_infos['rent_rule'] = $rent_rule;
$abprf_infos['location'] = $location;
$abprf_infos['date_info'] = $date_info;
$ticket_info = self::get_ticket_info( $abprf_infos );
$additional_infos = self::get_additional_info( $post_id );
$rent_price = self::get_price( $ticket_info );
$ex_price = self::get_additional_price( $additional_infos );
$deposit = self::get_deposit_price( $ticket_info );
$total_price = $rent_price + $ex_price + $deposit;
$cart_item['post_id'] = $post_id;
$cart_item['start_time'] = $start_time;
$cart_item['end_time'] = $end_time;
$cart_item['rent_rule'] = $rent_rule;
$cart_item['location'] = $location;
$cart_item['duration'] = $date_info['text'] ?? '';
$cart_item['ticket_info'] = $ticket_info;
$cart_item['additional_info'] = $additional_infos;
$cart_item['pass_info'] = self::get_passenger_info( $post_id );
$cart_item['rent'] = $rent_price;
$cart_item['ex_price'] = $ex_price;
$cart_item['deposit'] = $deposit;
$cart_item['total_price'] = $total_price;
$cart_item['line_total'] = $total_price;
$cart_item['line_subtotal'] = $total_price;
$cart_item = apply_filters( 'abprf_add_cart_item_data', $cart_item, $post_id );
if ( function_exists( 'wc_add_notice' ) && ! is_admin() ) {
wc_add_notice( get_the_title( $post_id ) . ' ' . __( 'Add to cart successfully!', 'abp-rentalforge' ), 'success' );
}
}
//echo '
';print_r( $cart_item); echo '
';die();
return $cart_item;
}
public function before_calculate_totals( $cart_object ): void {
foreach ( $cart_object->cart_contents as $value ) {
$post_id = $value['post_id'] ?? 0;
if ( get_post_type( $post_id ) == ABPRF_Function::get_cpt() ) {
$total_price = $value['total_price'] ?? 0;
$value['data']->set_price( $total_price );
$value['data']->set_regular_price( $total_price );
$value['data']->set_sale_price( $total_price );
$value['data']->set_sold_individually( 'yes' );
$value['data']->get_price();
}
}
}
public function cart_item_thumbnail( $thumbnail, $cart_item, $item_key ) {
$post_id = $cart_item['post_id'] ?? 0;
if ( get_post_type( $post_id ) == ABPRF_Function::get_cpt() ) {
$url = ABPRF_Function::get_image_url( $post_id ) ?: ABPRF_BLANK_IMG_URL;
if ( ! empty( $url ) ) {
$thumbnail = '';
}
}
return $thumbnail;
}
public function get_item_data( $item_data, $cart_item ) {
$post_id = $cart_item['post_id'] ?? 0;
if ( get_post_type( $post_id ) == ABPRF_Function::get_cpt() ) {
global $post;
$is_block_cart = false;
$is_block_checkout = false;
if ( is_a( $post, 'WP_Post' ) ) {
$is_block_cart = has_block( 'woocommerce/cart', $post->ID );
$is_block_checkout = has_block( 'woocommerce/checkout', $post->ID );
}
$cart_item = apply_filters( 'abprf_modify_cart_date', $cart_item );
if ( is_checkout() && $is_block_checkout ) {
$item_data = $this->display_cart_item_block( $cart_item );
} elseif ( is_cart() && $is_block_cart ) {
$item_data = $this->display_cart_item_block( $cart_item );
} else {
ob_start();
do_action( 'abprf_display_cart_item', $cart_item );
$content = ob_get_clean();
if ( ! empty( $content ) ) {
$item_data[] = array(
'name' => __( 'Booking Details', 'abp-rentalforge' ),
'value' => $content
);
}
}
}
return $item_data;
}
public static function get_ticket_info( $abprf_infos = [] ) {
$booking_info = [];
if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'abprf_registration_nonce' ) ) {
$post_int_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'absint', wp_unslash( $_POST[ $key ] ) ) : [];
$post_array = fn( $key ) => ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST[ $key ] ) ) : [];
$post_id = $abprf_infos['post_id'] ?? '';
$start_time = $abprf_infos['start_time'] ?? '';
$end_time = $abprf_infos['end_time'] ?? '';
$rent_rule = $abprf_infos['rent_rule'] ?? '';
$date_info = $abprf_infos['date_info'] ?? [];
$property_ids = $post_int_array( 'property_id' );
$property_check = $post_array( 'property_check' );
$property_qty = $post_int_array( 'property_qty' );
if ( ! empty( $start_time ) && ! empty( $end_time ) && ! empty( $rent_rule ) && ! empty( $date_info ) && sizeof( $date_info ) > 0 && ! empty( $property_ids ) && ! empty( $property_check ) && ! empty( $property_qty ) && ! empty( $post_id ) ) {
if ( sizeof( $property_check ) > 0 ) {
foreach ( $property_check as $key => $check ) {
$property_id = $property_ids[ $key ] ?? '';
$qty = $property_qty[ $key ] ?? '';
if ( ! empty( $check ) && ! empty( $property_id ) && ! empty( $qty ) ) {
$property = current( ABPRF_Query::get_property( [ 'property_id' => $property_id,'post_id'=>$post_id] ) );
if ( ! empty( $property ) ) {
$abprf_infos['property_id'] = $property_id;
$abprf_infos['qty'] = $qty;
$price = ABPRF_Function::get_price( $abprf_infos, $property );
$abprf_infos['price'] = $price;
$booking_info[ $property_id ]['name'] = $property['name'] ?? '';
$booking_info[ $property_id ]['price'] = $price;
$booking_info[ $property_id ]['deposit'] = ABPRF_Function::get_deposit_price( $abprf_infos, $property );
$booking_info[ $property_id ]['qty'] = $qty;
$booking_info[ $property_id ]['brand'] = $property['brand'] ?? '';
}
}
}
}
}
}
return apply_filters( 'abprf_cart_booking_info_filter', $booking_info );
}
public static function get_price( $ticket_infos ) {
$price = 0;
if ( is_array( $ticket_infos ) && sizeof( $ticket_infos ) > 0 ) {
foreach ( $ticket_infos as $ticket_info ) {
$ticket_price = $ticket_info['price'] ?? 0;
$price = $price + $ticket_price;
}
}
return $price;
}
public static function get_deposit_price( $ticket_infos ) {
$price = 0;
if ( is_array( $ticket_infos ) && sizeof( $ticket_infos ) > 0 ) {
foreach ( $ticket_infos as $ticket_info ) {
$ticket_price = $ticket_info['deposit'] ?? 0;
$price = $price + $ticket_price;
}
}
return $price;
}
public static function get_additional_price( $services ) {
$price = 0;
if ( is_array( $services ) && sizeof( $services ) > 0 ) {
foreach ( $services as $service ) {
$qty = $service['qty'] ?? '';
if ( ! empty( $qty ) && $qty > 0 ) {
$ticket_price = $service['price'] ?? 0;
$price = $price + $ticket_price * $qty;
}
}
}
return $price;
}
public static function get_additional_info( $post_id ): array {
$infos = array();
if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'abprf_registration_nonce' ) ) {
$display = ABPRF_Function::get_post_info( $post_id, 'display_additional_services', 'on' );
$active_global_additional = ABPRF_Function::get_post_info( $post_id, 'active_global_additional', 'on' );
if ( $active_global_additional == 'on' ) {
$services = ABPRF_Function::get_option( 'abprf_additional' );
} else {
$services = ABPRF_Function::get_post_info( $post_id, 'abprf_additional', [] );
}
if ( $display == 'on' && sizeof( $services ) > 0 ) {
$abprf_infos['display_additional_services'] = $display;
$abprf_infos['active_global_additional'] = $active_global_additional;
$abprf_infos['abprf_additional'] = $services;
foreach ( $services as $id => $service ) {
$name = isset( $_POST[ 'name_' . $id ] ) ? sanitize_text_field( wp_unslash( $_POST[ 'name_' . $id ] ) ) : '';
$quantity = isset( $_POST[ 'qty_' . $id ] ) ? sanitize_text_field( wp_unslash( $_POST[ 'qty_' . $id ] ) ) : '';
if ( ! empty( $name ) && ! empty( $quantity ) && $quantity > 0 ) {
$infos[ $id ]['name'] = $name;
$infos[ $id ]['qty'] = $quantity;
$infos[ $id ]['price'] = ABPRF_Function::get_additional_price( $post_id, $name, $abprf_infos );
$infos[ $id ]['icon'] = $service['icon'] ?? '';
$infos[ $id ]['returnable'] = $service['returnable'] ?? 'no';
}
}
}
}
return $infos;
}
public static function get_passenger_info( $post_id ): array {
$pass_info = [];
if (ABPRF_Function::on_off( 'client_info' ) && isset( $_POST['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'abprf_registration_nonce' ) ) {
$display = ABPRF_Function::get_post_info( $post_id, 'display_client_form', 'on' );
$active_global = ABPRF_Function::get_post_info( $post_id, 'active_global_form', 'on' );
if ( $active_global == 'on' ) {
$forms = ABPRF_Function::get_option( 'abprf_forms' );
} else {
$forms = ABPRF_Function::get_post_info( $post_id, 'abprf_forms', [] );
}
if ( $display == 'on' && sizeof( $forms ) > 0 ) {
foreach ( $forms as $id => $form ) {
$info = isset( $_POST[ $id ] ) ? sanitize_text_field( wp_unslash( $_POST[ $id ] ) ) : '';
$pass_info[ $id ]['label'] = $form['label'] ?? '';
$pass_info[ $id ]['value'] = $info;
}
}
}
return $pass_info;
}
public function display_cart_item_block( $cart_item ): array {
$start_time = $cart_item['start_time'] ?? '';
$end_time = $cart_item['end_time'] ?? '';
$duration = $cart_item['duration'] ?? '';
$location = $cart_item['location'] ?? '';
$ticket_infos = $cart_item['ticket_info'] ?? [];
$additional_info = $cart_item['additional_info'] ?? [];
$attendee_infos = $cart_item['pass_info'] ?? [];
$item_data = [];
if ( ! empty( $ticket_infos ) && sizeof( $ticket_infos ) > 0 ) {
$item_data[] = array( 'name' => __( 'Booking Information', 'abp-rentalforge' ), 'value' => '
' );
$item_data[] = array( 'name' => __( 'Rent Start', 'abp-rentalforge' ), 'value' => ABPRF_Function::date_format( $start_time ) . '
' );
$item_data[] = array( 'name' => __( 'Rent End', 'abp-rentalforge' ), 'value' => ABPRF_Function::date_format( $end_time ) . '
' );
$item_data[] = array( 'name' => __( 'Duration', 'abp-rentalforge' ), 'value' => $duration . '
' );
if ( ABPRF_Function::on_off( 'location' ) && ! empty( $location ) ) {
$item_data[] = array( 'name' => __( 'Location', 'abp-rentalforge' ), 'value' => ABPRF_Function::location_value( $location ) . '
' );
}
$item_data[] = array( 'name' => __( 'Property Information', 'abp-rentalforge' ), 'value' => '
' );
foreach ( $ticket_infos as $key => $ticket_info ) {
$item_data[] = array( 'name' => __( 'Name', 'abp-rentalforge' ), 'value' => $ticket_info['name'] . '
' );
$item_data[] = array( 'name' => __( 'Quantity', 'abp-rentalforge' ), 'value' => $ticket_info['qty'] . '
' );
$price = $ticket_info['price'] ?? 0;
$price = $price > 0 ? wc_price( $price ) : __( 'FREE', 'abp-rentalforge' );
$item_data[] = array( 'name' => __( 'Rent', 'abp-rentalforge' ), 'value' => $price . '
' );
$deposit = $ticket_info['deposit'] ?? '';
if (ABPRF_Function::on_off( 'deposit' ) && ! empty( $deposit ) ) {
$item_data[] = array( 'name' => __( 'Deposit', 'abp-rentalforge' ), 'value' => wc_price( $deposit ) . '
' );
}
$brand = $ticket_info['brand'] ?? '';
if ( ! empty( $brand ) && ABPRF_Function::on_off( 'brand' ) ) {
$item_data[] = array( 'name' => ABPRF_Function::brand_label(), 'value' => ABPRF_Function::brand_value( $brand ) . '
' );
}
$item_data = apply_filters( 'abprf_cart_property_info_block', $item_data, $cart_item, $key );
}
if (ABPRF_Function::on_off( 'additional_info' ) && ! empty( $additional_info ) && sizeof( $additional_info ) > 0 ) {
$item_data[] = array( 'name' => __( 'Additional Information', 'abp-rentalforge' ), 'value' => '
' );
foreach ( $additional_info as $additional ) {
if ( is_array( $additional ) ) {
$qty = $additional['qty'] ?? 1;
$price = $additional['price'] ?? 0;
$price_text = $price > 0 ? wc_price( $price ) : __( 'FREE', 'abp-rentalforge' );
$ex_price = $price > 0 ? wc_price( $price * $qty ) : __( 'FREE', 'abp-rentalforge' );
$item_data[] = array( 'name' => $additional['name'] ?? '', 'value' => $price_text . ' X ' . $qty . ' = ' . $ex_price . '
' );
}
}
}
if (ABPRF_Function::on_off( 'client_info' ) && ! empty( $attendee_infos ) && sizeof( $attendee_infos ) > 0 ) {
$item_data[] = array( 'name' => __( 'Client Information', 'abp-rentalforge' ), 'value' => '
' );
foreach ( $attendee_infos as $attendee_info ) {
$label = $attendee_info['label'] ?? '';
$value = $attendee_info['value'] ?? '';
if ( $label && $value ) {
$item_data[] = array( 'name' => $label, 'value' => $value . '
' );
}
}
}
}
return $item_data;
}
//=============================//
public function after_checkout_validation(): void {
global $woocommerce;
$cart_items = $woocommerce->cart->get_cart();
foreach ( $cart_items as $cart_item_key => $cart_item ) {
$post_id = $cart_item['post_id'] ?? 0;
if ( get_post_type( $post_id ) == ABPRF_Function::get_cpt() ) {
$location = $cart_item['location'] ?? '';
$rent_rule = $cart_item['rent_rule'] ?? '';
$abprf_infos['post_id'] = $cart_item['post_id'] ?? '';
$abprf_infos['rent_rule'] = $rent_rule;
$abprf_infos['start_time'] = $cart_item['start_time'] ?? '';
$abprf_infos['end_time'] = $cart_item['end_time'] ?? '';
$abprf_infos['location'] = $location;
$ticket_infos = $cart_item['ticket_info'] ?? [];
if ( sizeof( $ticket_infos ) > 0 && ABPRF_Function::check_date_exit( $abprf_infos ) ) {
foreach ( $ticket_infos as $id => $ticket_info ) {
$qty = $ticket_info['qty'] ?? '';
if ( ! empty( $qty ) && $qty > 0 ) {
$abprf_infos['property_id'] = $id;
$sold_qty = ABPRF_Query::get_sold_qty( $abprf_infos );
$property = current( ABPRF_Query::get_property( [ 'property_id' => $id , 'post_id'=>$post_id ] ) );
$price_qty_info = json_decode( $property['price_qty_info'] ?? '', true ) ?: [];
$price_qty_info = ( ! empty( $location ) && isset( $price_qty_info[ $location ] ) ) ? $price_qty_info[ $location ] : $price_qty_info;
$price_info = $price_qty_info[ $rent_rule ] ?? [];
$total_qty = $price_info['qty'] ?? 0;
$reserve_qty = $price_info['reserve'] ?? 0;
$min_qty = ( ( $price_info['min_qty'] ?? 0 ) > 0 ) ? $price_info['min_qty'] : 1;
$max_qty = ( ( $price_info['max_qty'] ?? 0 ) > 0 ) ? $price_info['max_qty'] : 0;
$available_qty = $total_qty - $reserve_qty - $sold_qty;
$available_qty = $max_qty > 0 ? min( $max_qty, $available_qty ) : $available_qty;
if ( $qty < $min_qty || $qty > $available_qty ) {
$woocommerce->cart->remove_cart_item( $cart_item_key );
wc_add_notice( __( "Oh ! We are Sorry, Your Selected Item Already Booked by another . please Try another Item.", 'abp-rentalforge' ), 'error' );
}
}
}
} else {
$woocommerce->cart->remove_cart_item( $cart_item_key );
wc_add_notice( __( "Oh ! We are Sorry, Something Wrong. please Try another Time.", 'abp-rentalforge' ), 'error' );
}
}
}
}
public function checkout_create_order_line_item( $item, $key, $cart_item ): void {
$post_id = $cart_item['post_id'] ?? 0;
if ( get_post_type( $post_id ) == ABPRF_Function::get_cpt() ) {
$rent_rule = $cart_item['rent_rule'] ?? '';
$start_time = $cart_item['start_time'] ?? '';
$end_time = $cart_item['end_time'] ?? '';
$book_from = ( $rent_rule == 'daily' || $rent_rule == 'monthly' ) ? $start_time : ABPRF_Function::booking_buffer( $start_time );
$book_to = ( $rent_rule == 'daily' || $rent_rule == 'monthly' ) ? $end_time : ABPRF_Function::booking_buffer( $end_time, true );
$cart_item = apply_filters( 'abprf_modify_cart_date', $cart_item );
$start_time = $cart_item['start_time'] ?? '';
$end_time = $cart_item['end_time'] ?? '';
$duration = $cart_item['duration'] ?? '';
$location = $cart_item['location'] ?? '';
$ticket_infos = $cart_item['ticket_info'] ?? [];
$additional_infos = $cart_item['additional_info'] ?? [];
$attendee_infos = $cart_item['pass_info'] ?? [];
if ( ! empty( $ticket_infos ) && sizeof( $ticket_infos ) > 0 ) {
$item->add_meta_data( __( 'Booking Information', 'abp-rentalforge' ), '' );
$item->add_meta_data( __( 'Rent Start', 'abp-rentalforge' ), ABPRF_Function::date_format( $start_time ) );
$item->add_meta_data( __( 'Rent End', 'abp-rentalforge' ), ABPRF_Function::date_format( $end_time ) );
$item->add_meta_data( __( 'Duration', 'abp-rentalforge' ), $duration );
if (ABPRF_Function::on_off( 'location' ) && ! empty( $location ) ) {
$item->add_meta_data( ABPRF_Function::location_label(), ABPRF_Function::location_value( $location ) );
}
$item->add_meta_data( __( 'Property Information', 'abp-rentalforge' ), '' );
$all_brand = '';
foreach ( $ticket_infos as $ticket_info ) {
$item->add_meta_data( __( 'Property Name', 'abp-rentalforge' ), $ticket_info['name'] );
$item->add_meta_data( __( 'Quantity', 'abp-rentalforge' ), $ticket_info['qty'] );
$price = $ticket_info['price'] ?? 0;
$price = $price > 0 ? wc_price( $price ) : __( 'FREE', 'abp-rentalforge' );
$item->add_meta_data( __( 'Rent', 'abp-rentalforge' ), $price );
$deposit = $ticket_info['deposit'] ?? '';
if (ABPRF_Function::on_off( 'deposit' ) && ! empty( $deposit ) ) {
$item->add_meta_data( __( 'Deposit', 'abp-rentalforge' ), wc_price( $deposit ) );
}
$brand = $ticket_info['brand'] ?? '';
$all_brand = ! empty( $all_brand ) ? $all_brand . ',' . $brand : $brand;
if ( ! empty( $brand ) && ABPRF_Function::on_off( 'brand' ) ) {
$item->add_meta_data( ABPRF_Function::brand_label(), ABPRF_Function::brand_value( $brand ) );
}
}
if (ABPRF_Function::on_off( 'additional_info' ) && ! empty( $additional_infos ) && sizeof( $additional_infos ) > 0 ) {
$item->add_meta_data( __( 'Additional Information', 'abp-rentalforge' ), '' );
foreach ( $additional_infos as $additional ) {
$name = $additional['name'] ?? '';
$qty = $additional['qty'] ?? 1;
$price = $additional['price'] ?? 0;
$price_text = $price > 0 ? wc_price( $price ) : __( 'FREE', 'abp-rentalforge' );
if ( ! empty( $name ) && $qty > 0 ) {
$ex_price = $price > 0 ? wc_price( $price * $qty ) : __( 'FREE', 'abp-rentalforge' );
$item->add_meta_data( $name, ' ( ' . $price_text . ' X ' . $qty . ') = ' . $ex_price );
}
}
}
if (ABPRF_Function::on_off( 'client_info' ) && ! empty( $attendee_infos ) && sizeof( $attendee_infos ) > 0 ) {
$item->add_meta_data( __( 'Client Information', 'abp-rentalforge' ), '' );
foreach ( $attendee_infos as $attendee_info ) {
$label = $attendee_info['label'] ?? '';
$value = $attendee_info['value'] ?? '';
if ( ! empty( $label ) && ! empty( $value ) ) {
$item->add_meta_data( $label, $value );
}
}
}
//=============================//
$item_info = [
'post_id' => $post_id,
'user_id' => get_current_user_id(),
'start_time' => $start_time,
'end_time' => $end_time,
'book_from' => $book_from,
'book_to' => $book_to,
'duration' => $duration,
'location' => $location,
'brand' => $all_brand,
'rent_rule' => $rent_rule,
'ticket_info' => $ticket_infos,
'additional_info' => $additional_infos,
'pass_info' => $attendee_infos,
'rent' => $cart_item['rent'] ?? '',
'ex_price' => $cart_item['ex_price'] ?? '',
'deposit' => $cart_item['deposit'] ?? '',
'item_total' => $cart_item['total_price'] ?? '',
];
$item_info = apply_filters( 'abprf_checkout_create_order_line_item', $item_info, $cart_item );
$item->add_meta_data( '_abprf_items', $item_info, true );
}
}
}
public static function save_custom_data( $order_id ): void {
if ( $order_id ) {
$order = wc_get_order( $order_id );
$order_status = $order->get_status();
$payment_method = $order->get_payment_method_title();
$user_id = $order->get_user_id();
$billing_first_name = $order->get_billing_first_name();
$billing_last_name = $order->get_billing_last_name();
$billing_email = $order->get_billing_email();
$billing_phone = $order->get_billing_phone();
$billing_address_1 = $order->get_billing_address_1();
$billing_address_2 = $order->get_billing_address_2();
$billing_name = $billing_first_name . ' ' . $billing_last_name;
$billing_address = $billing_address_1 . ' ' . $billing_address_2;
$booked_status = ABPRF_Function::booking_status();
$booked_status = $booked_status ? explode( ',', $booked_status ) : [];
if ( $order_status != 'failed' ) {
$total_order = ABPRF_Query::get_booking_query( [ 'order_id' => $order_id ], 0, 0, true );
if ( $total_order == 0 ) {
foreach ( $order->get_items() as $item_id => $item ) {
$item_info = wc_get_order_item_meta( $item_id, '_abprf_items' );
if ( ! empty( $item_info ) && is_array( $item_info ) && sizeof( $item_info ) > 0 ) {
$post_id = $item_info['post_id'] ?? '';
if ( ! empty( $post_id ) && get_post_type( $post_id ) == ABPRF_Function::get_cpt() ) {
$ticket_infos = $item_info['ticket_info'] ?? [];
$start_time = $item_info['start_time'] ?? '';
$end_time = $item_info['end_time'] ?? '';
$book_from = $item_info['book_from'] ?? '';
$book_to = $item_info['book_to'] ?? '';
$additional_info = $item_info['additional_info'] ?? '';
global $wpdb;
$table_name = $wpdb->prefix . 'abprf_orders';
if ( ! empty( $ticket_infos ) && sizeof( $ticket_infos ) > 0 ) {
$property_id = $ex_id = [];
foreach ( $ticket_infos as $key => $ticket_info ) {
$property_id[] = $key;
}
if ( ! empty( $additional_info ) && sizeof( $additional_info ) > 0 ) {
foreach ( $additional_info as $key => $additional ) {
$ex_id[] = $key;
}
}
$price_info['rent'] = $item_info['rent'] ?? '';
$price_info['ex_price'] = $item_info['ex_price'] ?? '';
$price_info['deposit'] = $item_info['deposit'] ?? '';
$price_info['item_total'] = $item_info['item_total'] ?? '';
$others['rent_rule'] = $item_info['rent_rule'] ?? '';
$others['duration'] = $item_info['duration'] ?? '';
$_order_status = 'wc-' . $order_status;
$data = [
'order_id' => intval( $order_id ),
'item_id' => intval( $item_id ),
'post_id' => intval( $post_id ),
'user_id' => intval( $user_id ),
'property_id' => wp_json_encode( $property_id ),
'ex_id' => wp_json_encode( $ex_id ),
'start_time' => sanitize_text_field( $start_time ),
'end_time' => sanitize_text_field( $end_time ),
'book_from' => sanitize_text_field( $book_from ),
'book_to' => sanitize_text_field( $book_to ),
'category' => sanitize_text_field( get_post_meta( $post_id, 'abprf_category', true ) ),
'location' => sanitize_text_field( $item_info['location'] ?? '' ),
'brand' => sanitize_text_field( $item_info['brand'] ?? '' ),
'price_info' => wp_json_encode( $price_info ),
'property_info' => wp_json_encode( $ticket_infos ),
'ex_info' => wp_json_encode( $additional_info ),
'pass_info' => wp_json_encode( $item_info['pass_info'] ?? [] ),
'delivery_option' => 0,
'book_status' => in_array( $_order_status, $booked_status ) ? 1 : 0,
'order_status' => sanitize_text_field( $_order_status ),
'payment_method' => sanitize_text_field( $payment_method ),
'billing_name' => sanitize_text_field( $billing_name ),
'billing_email' => sanitize_text_field( $billing_email ),
'billing_phone' => sanitize_text_field( $billing_phone ),
'billing_address' => sanitize_text_field( $billing_address ),
'others' => wp_json_encode( $others ),
'created_at' => current_time( 'Y-m-d H:i' ),
'updated_at' => current_time( 'Y-m-d H:i' )
];
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->insert( $table_name, $data );
}
}
}
}
}
}
}
}
public function checkout_order_processed( $order_id ): void {
self::save_custom_data( $order_id );
}
public function api_checkout_order_processed( $order ): void {
$this->checkout_order_processed( $order->get_id() );
}
public function order_status_changed( $order_id ): void {
if ( ! empty( $order_id ) && $order_id > 0 ) {
global $wpdb;
$table_name = $wpdb->prefix . 'abprf_orders';
$order = wc_get_order( $order_id );
$order_status = $order->get_status();
foreach ( $order->get_items() as $item_id => $item_values ) {
if ( $item_id ) {
$order_infos = ABPRF_Query::get_booking_query( [ 'item_id' => $item_id ] );
if ( ! empty( $order_infos ) && sizeof( $order_infos ) > 0 ) {
$order_info = current( $order_infos );
$others = $order_info['others'] ?? '';
if ( ! empty( $others ) ) {
$others = json_decode( $others, true );
$user_id = get_current_user_id();
$others['updated_by'] = $user_id;
$data = [
'others' => wp_json_encode( $others ),
'order_status' => 'wc-' . $order_status,
'updated_at' => current_time( 'Y-m-d H:i' )
];
$where = [ 'item_id' => $item_id ];
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->update( $table_name, $data, $where, [ '%s', '%s', '%s' ], [ '%d' ] );
$mail_send = apply_filters( 'abprf_send_mail', false, $item_id );
}
}
}
}
}
}
}
new ABPRF_Woocommerce();
}