1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
<?php
class prdd_adminevent_jsons {
public static function prdd_adminevent_event_jsons() {
if( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'prdd-adminend-events-jsons' ) {
global $wpdb;
$data = array();
$query_get_order_item_ids = "SELECT order_item_id FROM `" . $wpdb->prefix . "woocommerce_order_itemmeta` WHERE meta_key = '_prdd_date'";
$get_order_item_ids = $wpdb->get_results( $query_get_order_item_ids );
if ( is_array( $get_order_item_ids ) && count( $get_order_item_ids ) > 0 ) {
foreach ( $get_order_item_ids as $item_key => $item_value ) {
$time_slot = $date = $product_id = $from_time = $to_time = '';
$value = new stdClass();
$query_order_id = "SELECT order_id FROM `" . $wpdb->prefix . "woocommerce_order_items`
WHERE order_item_id = %d";
$get_order_id = $wpdb->get_results( $wpdb->prepare( $query_order_id, $item_value->order_item_id ) );
if( 'shop_order' == get_post_type( $get_order_id[0]->order_id ) ) {
$order = new WC_Order( $get_order_id[0]->order_id );
}
if( version_compare( get_option( 'woocommerce_version ' ), '3.0.0', ">=" ) ) {
$order_post_status = $order->get_status();
if( $order_post_status != 'trash' ) {
$order_post_status = "wc-" . $order_post_status;
}
} else {
$order_post_status = $order->post_status;
}
if( isset( $order_post_status ) && ( $order_post_status != '' ) && ( $order_post_status != 'wc-cancelled' ) && ( $order_post_status != 'wc-refunded' ) && ( $order_post_status != 'trash' ) && ( $order_post_status != 'wc-failed' ) ) {
$query_get_dates = "SELECT meta_value, meta_key FROM `" . $wpdb->prefix . "woocommerce_order_itemmeta`
WHERE meta_key IN (%s,%s,%s)
AND order_item_id = %d";
$get_dates = $wpdb->get_results( $wpdb->prepare( $query_get_dates, '_prdd_date', '_prdd_time_slot', '_product_id', $item_value->order_item_id ) );
foreach ( $get_dates as $k => $v ) {
if( $v->meta_key == '_prdd_date' ) {
$date = $v->meta_value;
}
if ( $v->meta_key == '_prdd_time_slot' ) {
$time_slot = $v->meta_value;
}
if ( $v->meta_key == '_product_id' ) {
$product_id = $v->meta_value;
}
}
$value->post_id = $product_id;
$value->delivery_date = $date;
$product_name = html_entity_decode( get_the_title( $product_id ) , ENT_COMPAT, 'UTF-8' );
$time_slot_arr = explode( " - ", $time_slot );
if( isset( $time_slot_arr[ 0 ] ) && $time_slot_arr[ 0 ] != '' ) {
$from_time = $time_slot_arr[ 0 ];
$value->from_time = $from_time;
}
if( isset( $time_slot_arr[ 1 ] ) && $time_slot_arr[ 1 ] != '' ) {
$to_time = $time_slot_arr[ 1 ];
$value->to_time = $to_time;
}
if( $from_time != "" && $to_time != "" ) {
$date_from_time = $date;
$date_from_time .= " ".$from_time;
$post_from_timestamp = strtotime( $date_from_time );
$post_from_date = date ( 'Y-m-d H:i:s', $post_from_timestamp );
$date_to_time = $date;
$date_to_time .= " ".$to_time;
$post_to_timestamp = strtotime( $date_to_time );
$post_to_date = date ( 'Y-m-d H:i:s', $post_to_timestamp );
array_push( $data, array(
'id' => $get_order_id[0]->order_id,
'title' => $product_name,
'start' => $post_from_date,
'end' => $post_to_date,
'value' => $value
));
} else if( $from_time != "" ) {
$date_from_time = $date;
$date_from_time .= " ".$from_time;
$post_from_timestamp = strtotime( $date_from_time );
$post_from_date = date ( 'Y-m-d H:i:s', $post_from_timestamp );
$time = strtotime( $from_time );
$endTime = date( "H:i", strtotime( '+30 minutes', $time ) );
$date_to_time = $date;
$date_to_time .= " ".$endTime;
$post_to_timestamp = strtotime( $date_to_time );
$post_to_date = date ( 'Y-m-d H:i:s', $post_to_timestamp );
array_push( $data, array(
'id' => $get_order_id[0]->order_id,
'title' => $product_name,
'start' => $post_from_date,
'end' => $post_to_date,
'value' => $value
));
} else {
array_push( $data, array(
'id' => $get_order_id[0]->order_id,
'title' => $product_name,
'start' => $date,
'end' => $date,
'value' => $value
));
}
}
}
}
echo json_encode( $data );
}
}
}
$prdd_adminevent_jsons = new prdd_adminevent_jsons();