From 7e0e106a8151b6bc66dcf7a1eb728341060c42b2 Mon Sep 17 00:00:00 2001 From: Kapil Paul Date: Sat, 25 Feb 2023 13:16:31 +0600 Subject: [PATCH] added original order number in ecourier metabox --- assets/js/admin.js | 1 + .../Admin/views/ste-booking-metabox-view.php | 1 + includes/Ajax.php | 24 +++++++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 4c4e01e..361a09d 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -87,6 +87,7 @@ number_of_item: $( "#number_of_item", bookingFormWrap ).val(), comments: $( "#comments", bookingFormWrap ).val(), submit_ste_ecourier_parcel: $( "#submit_ste_ecourier_parcel", bookingFormWrap ).val(), + original_order_number: $( "#original_order_number", bookingFormWrap ).val(), action: 'ste_booking_metabox_form', _nonce: STE_ADMIN.nonce, }; diff --git a/includes/Admin/views/ste-booking-metabox-view.php b/includes/Admin/views/ste-booking-metabox-view.php index 89c4ab5..e23c97e 100644 --- a/includes/Admin/views/ste-booking-metabox-view.php +++ b/includes/Admin/views/ste-booking-metabox-view.php @@ -100,6 +100,7 @@ +
diff --git a/includes/Ajax.php b/includes/Ajax.php index 81a6ebe..3454f4a 100644 --- a/includes/Ajax.php +++ b/includes/Ajax.php @@ -156,9 +156,9 @@ public function handle_booking_metabox_form_submission() { $parcel_data = array( 'recipient_name' => sanitize_text_field( wp_unslash( $_POST['recipient_name'] ) ), 'recipient_mobile' => sanitize_text_field( wp_unslash( $_POST['recipient_mobile'] ) ), - 'recipient_city' => sanitize_text_field( wp_unslash( $_POST['recipient_city'] ) ), - 'recipient_area' => sanitize_text_field( wp_unslash( $_POST['recipient_area'] ) ), - 'recipient_thana' => sanitize_text_field( wp_unslash( $_POST['recipient_thana'] ) ), + 'recipient_city' => ucwords( sanitize_text_field( wp_unslash( $_POST['recipient_city'] ) ) ), + 'recipient_area' => ucwords( sanitize_text_field( wp_unslash( $_POST['recipient_area'] ) ) ), + 'recipient_thana' => ucwords( sanitize_text_field( wp_unslash( $_POST['recipient_thana'] ) ) ), 'recipient_zip' => sanitize_text_field( wp_unslash( $_POST['recipient_zip'] ) ), 'recipient_address' => sanitize_text_field( wp_unslash( $_POST['recipient_address'] ) ), 'payment_method' => sanitize_text_field( wp_unslash( $_POST['payment_method'] ) ), @@ -174,6 +174,14 @@ public function handle_booking_metabox_form_submission() { // Send parcel booking request to eCourier. $response = $this->make_request( $ecourier_api_url, $parcel_data ); + if ( is_wp_error( $response ) ) { + wp_send_json_error( + array( + 'message' => $response->get_error_data(), + ) + ); + } + $result = json_decode( $response['body'], true ); if ( $result['success'] ) { @@ -194,8 +202,14 @@ public function handle_booking_metabox_form_submission() { ); } - // Get the order to update the order status. - $order = new \WC_Order( $parcel_data['product_id'] ); + /** + * Get the order to update the order status. + * + * using original order number here because sometimes the order + * number might be modified through `woocommerce_order_number` filter + * by third party plugin. + */ + $order = new \WC_Order( sanitize_text_field( wp_unslash( $_POST['original_order_number'] ) ) ); $order->update_status( 'shipped' ); }