From b9547eceab642f26d7a4d99f65fe9c6b7fd3120f Mon Sep 17 00:00:00 2001 From: vendidero Date: Wed, 24 Jul 2024 10:57:44 +0200 Subject: [PATCH] Link to last shipment's tracking URL within the shipping status order column, in case available. --- src/Admin/Admin.php | 6 +++++- src/Order.php | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Admin/Admin.php b/src/Admin/Admin.php index 5a01cee..8428f30 100644 --- a/src/Admin/Admin.php +++ b/src/Admin/Admin.php @@ -592,7 +592,11 @@ public static function render_order_columns( $column, $post_id ) { $status_html = '' . esc_html( wc_gzd_get_shipment_order_shipping_status_name( $shipping_status ) ) . ''; if ( in_array( $shipping_status, array( 'shipped', 'partially-shipped' ), true ) && $shipment_order->get_shipments() ) { - echo '' . wp_kses_post( $status_html ) . ''; + if ( $last_shipment = $shipment_order->get_last_shipment_with_tracking() ) { + echo '' . wp_kses_post( $status_html ) . ''; + } else { + echo '' . wp_kses_post( $status_html ) . ''; + } } else { echo wp_kses_post( $status_html ); } diff --git a/src/Order.php b/src/Order.php index c2283b5..31c9ad3 100644 --- a/src/Order.php +++ b/src/Order.php @@ -89,16 +89,29 @@ public function is_shipped() { return apply_filters( 'woocommerce_gzd_shipment_order_shipping_status', ( in_array( $shipping_status, array( 'shipped', 'delivered' ), true ) || ( 'partially-delivered' === $shipping_status && ! $this->needs_shipping( array( 'sent_only' => true ) ) ) ), $this ); } - public function get_last_tracking_id() { - $tracking_id = ''; + /** + * @return Shipment|false + */ + public function get_last_shipment_with_tracking() { + $last_shipment = false; foreach ( array_reverse( $this->get_simple_shipments( true ) ) as $shipment ) { if ( ! empty( $shipment->get_tracking_id() ) ) { - $tracking_id = $shipment->get_tracking_id(); + $last_shipment = $shipment; break; } } + return apply_filters( 'woocommerce_gzd_shipment_order_last_shipment_with_tracking', $last_shipment, $this ); + } + + public function get_last_tracking_id() { + $tracking_id = ''; + + if ( $last_shipment = $this->get_last_shipment_with_tracking() ) { + $tracking_id = $last_shipment->get_tracking_id(); + } + return apply_filters( 'woocommerce_gzd_shipment_order_last_tracking_id', $tracking_id, $this ); }