Skip to content

Commit

Permalink
Link to last shipment's tracking URL within the shipping status order…
Browse files Browse the repository at this point in the history
… column, in case available.
  • Loading branch information
dennisnissle committed Jul 24, 2024
1 parent 0d6de49 commit b9547ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,11 @@ public static function render_order_columns( $column, $post_id ) {
$status_html = '<span class="order-shipping-status status-' . esc_attr( $shipping_status ) . '">' . esc_html( wc_gzd_get_shipment_order_shipping_status_name( $shipping_status ) ) . '</span>';

if ( in_array( $shipping_status, array( 'shipped', 'partially-shipped' ), true ) && $shipment_order->get_shipments() ) {
echo '<a target="_blank" href="' . esc_url( add_query_arg( array( 'order_id' => $the_order->get_id() ), admin_url( 'admin.php?page=wc-gzd-shipments' ) ) ) . '">' . wp_kses_post( $status_html ) . '</a>';
if ( $last_shipment = $shipment_order->get_last_shipment_with_tracking() ) {
echo '<a target="_blank" href="' . esc_url( $last_shipment->get_tracking_url() ) . '" class="help_tip" data-tip="' . esc_attr( $last_shipment->get_tracking_id() ) . '">' . wp_kses_post( $status_html ) . '</a>';
} else {
echo '<a target="_blank" href="' . esc_url( add_query_arg( array( 'order_id' => $the_order->get_id() ), admin_url( 'admin.php?page=wc-gzd-shipments' ) ) ) . '" class="help_tip" data-tip="">' . wp_kses_post( $status_html ) . '</a>';
}
} else {
echo wp_kses_post( $status_html );
}
Expand Down
19 changes: 16 additions & 3 deletions src/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down

0 comments on commit b9547ec

Please sign in to comment.