diff --git a/includes/Admin/STE_Metabox.php b/includes/Admin/STE_Metabox.php index 9e4d865..7311830 100644 --- a/includes/Admin/STE_Metabox.php +++ b/includes/Admin/STE_Metabox.php @@ -18,7 +18,7 @@ class STE_Metabox { /** - * Hold all shipping information for eCourier. + * Holds all shipping information for eCourier. * * @var array */ @@ -58,9 +58,14 @@ public function metabox_view_handler() { wp_enqueue_style( 'ste-admin-styles' ); wp_enqueue_script( 'ste-admin-script' ); - // Set all necessary Shipping Information. - $this->set_shipping_info( $theorder ); + $order_shipped = ste_get_order_shipping_info( $theorder->get_order_number() ); + if ( ! $order_shipped ) { + // Set all necessary Shipping Information. + $this->set_shipping_info( $theorder ); + } else { + $order_shipped->user = get_user_by( 'ID', $order_shipped->created_by )->display_name; + } // Load the parcel booking form/view. if ( ! file_exists( __DIR__ . '/views/ste-booking-metabox-view.php' ) ) { diff --git a/includes/Admin/views/ste-booking-metabox-view.php b/includes/Admin/views/ste-booking-metabox-view.php index 108461e..e3824b0 100644 --- a/includes/Admin/views/ste-booking-metabox-view.php +++ b/includes/Admin/views/ste-booking-metabox-view.php @@ -8,6 +8,7 @@ ?>
+
-
-

-

+ +
+ style="display: block" + + > +

+ + created_at ) ) ); ?> + +

+ +

+ user ); ?> +

+ +

+ + + + tracking_id ); ?> + + +

diff --git a/includes/functions.php b/includes/functions.php index 32059cc..cac3968 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -103,3 +103,23 @@ function ste_insert_shipped_order( $args = array() ) { return true; } + +/** + * Check if the order is already shipped and return the status. + * + * @param int $order_id WC order number. + * + * @return array|object|bool + */ +function ste_get_order_shipping_info( $order_id ) { + global $wpdb; + + $table_name = $wpdb->prefix . STE_TABLE_PREFIX . 'shipped_orders'; + + $order_shipment_status = $wpdb->get_results( "SELECT * FROM `{$table_name}` WHERE `order_id`={$order_id}"); // phpcs:ignore + + if ( empty( $order_shipment_status ) ) { + return false; + } + return $order_shipment_status[0]; +}