Skip to content

Commit

Permalink
added original order number in ecourier metabox
Browse files Browse the repository at this point in the history
  • Loading branch information
kapilpaul committed Feb 25, 2023
1 parent 62de163 commit 7e0e106
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
1 change: 1 addition & 0 deletions includes/Admin/views/ste-booking-metabox-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<input type="hidden" name="product_price" id="product_price" value="<?php echo esc_attr( $this->shipping_info['product_price'] ); ?>">
<input type="hidden" name="number_of_item" id="number_of_item" value="<?php echo esc_attr( $this->shipping_info['number_of_item'] ); ?>">
<input type="hidden" name="comments" id="comments" value="<?php echo esc_attr( $this->shipping_info['comments'] ); ?>">
<input type="hidden" name="original_order_number" id="original_order_number" value="<?php echo esc_attr( $post->ID ); ?>">
</div>
<?php } ?>
<div id="ste-booking-metabox-message" <?php if ( $order_shipped ) { ?>
Expand Down
24 changes: 19 additions & 5 deletions includes/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ),
Expand All @@ -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'] ) {
Expand All @@ -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' );
}

Expand Down

0 comments on commit 7e0e106

Please sign in to comment.