Skip to content

Commit

Permalink
Order shipped info added to WC order view
Browse files Browse the repository at this point in the history
  • Loading branch information
simongomes committed Apr 28, 2021
1 parent 9d53dc2 commit 9607d02
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
11 changes: 8 additions & 3 deletions includes/Admin/STE_Metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class STE_Metabox {

/**
* Hold all shipping information for eCourier.
* Holds all shipping information for eCourier.
*
* @var array
*/
Expand Down Expand Up @@ -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' ) ) {
Expand Down
27 changes: 24 additions & 3 deletions includes/Admin/views/ste-booking-metabox-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
?>

<div id="ste-metabox-wrap">
<?php if ( ! $order_shipped ) { ?>
<div id="ste-booking-metabox-form">
<ul class="ste_metabox submitbox">
<li class="wide">
Expand Down Expand Up @@ -72,8 +73,28 @@
<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'] ); ?>">
</div>
<div id="ste-booking-metabox-message">
<h3 class="title"></h3>
<h4><?php esc_html_e( 'Tracking ID: ', 'ship-to-ecourier' ); ?> <span class="tracking_id"></span></h4>
<?php } ?>
<div id="ste-booking-metabox-message" <?php if ( $order_shipped ) { ?>
style="display: block"
<?php } ?>
>
<h3 class="title">
<?php if ( $order_shipped ) { ?>
<?php esc_html_e( 'Shipped On ', 'ship-to-ecourier' ); ?> <?php echo esc_html( gmdate( 'd F, Y', strtotime( $order_shipped->created_at ) ) ); ?>
<?php } ?>
</h3>
<?php if ( $order_shipped ) { ?>
<h4>
<?php esc_html_e( 'Shipped By ', 'ship-to-ecourier' ); ?> <?php echo esc_html( $order_shipped->user ); ?>
</h4>
<?php } ?>
<h4>
<?php esc_html_e( 'Tracking ID: ', 'ship-to-ecourier' ); ?>
<span class="tracking_id">
<?php if ( $order_shipped ) { ?>
<?php echo esc_html( $order_shipped->tracking_id ); ?>
<?php } ?>
</span>
</h4>
</div>
</div>
20 changes: 20 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

0 comments on commit 9607d02

Please sign in to comment.