Skip to content

Commit

Permalink
HPOS: Add descriptive document titles to HPOS order admin screens (#3…
Browse files Browse the repository at this point in the history
…8617)

* Set the Orders admin page titles

* Tweak edit order title, translator messages

* Add changelog file

* phpcs cleanup
  • Loading branch information
coreymckrill committed Jun 7, 2023
1 parent 99dbdbe commit 016d948
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/update-order-admin-page-titles
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Add descriptive document titles to HPOS order admin screens
43 changes: 43 additions & 0 deletions plugins/woocommerce/src/Internal/Admin/Orders/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public function setup(): void {
$page_suffix = ( 'shop_order' === $this->order_type ? '' : '--' . $this->order_type );

self::add_action( 'load-woocommerce_page_wc-orders' . $page_suffix, array( $this, 'handle_load_page_action' ) );
self::add_action( 'admin_title', array( $this, 'set_page_title' ) );
}

/**
Expand All @@ -160,6 +161,48 @@ private function handle_load_page_action() {
}
}

/**
* Set the document title for Orders screens to match what it would be with the shop_order CPT.
*
* @param string $admin_title The admin screen title before it's filtered.
*
* @return string The filtered admin title.
*/
private function set_page_title( $admin_title ) {
if ( ! $this->is_order_screen( $this->order_type ) ) {
return $admin_title;
}

$wp_order_type = get_post_type_object( $this->order_type );
$labels = get_post_type_labels( $wp_order_type );

if ( $this->is_order_screen( $this->order_type, 'list' ) ) {
$admin_title = sprintf(
// translators: 1: The label for an order type 2: The name of the website.
esc_html__( '%1$s ‹ %2$s — WordPress', 'woocommerce' ),
esc_html( $labels->name ),
esc_html( get_bloginfo( 'name' ) )
);
} elseif ( $this->is_order_screen( $this->order_type, 'edit' ) ) {
$admin_title = sprintf(
// translators: 1: The label for an order type 2: The title of the order 3: The name of the website.
esc_html__( '%1$s #%2$s ‹ %3$s — WordPress', 'woocommerce' ),
esc_html( $labels->edit_item ),
absint( $this->order->get_id() ),
esc_html( get_bloginfo( 'name' ) )
);
} elseif ( $this->is_order_screen( $this->order_type, 'new' ) ) {
$admin_title = sprintf(
// translators: 1: The label for an order type 2: The name of the website.
esc_html__( '%1$s ‹ %2$s — WordPress', 'woocommerce' ),
esc_html( $labels->add_new_item ),
esc_html( get_bloginfo( 'name' ) )
);
}

return $admin_title;
}

/**
* Determines the order type for the current screen.
*
Expand Down

0 comments on commit 016d948

Please sign in to comment.