diff --git a/plugins/woocommerce/changelog/update-order-admin-page-titles b/plugins/woocommerce/changelog/update-order-admin-page-titles new file mode 100644 index 000000000000..8b197c89e0f5 --- /dev/null +++ b/plugins/woocommerce/changelog/update-order-admin-page-titles @@ -0,0 +1,4 @@ +Significance: minor +Type: update + +Add descriptive document titles to HPOS order admin screens diff --git a/plugins/woocommerce/src/Internal/Admin/Orders/PageController.php b/plugins/woocommerce/src/Internal/Admin/Orders/PageController.php index bc34017ed908..1c7f93c773fc 100644 --- a/plugins/woocommerce/src/Internal/Admin/Orders/PageController.php +++ b/plugins/woocommerce/src/Internal/Admin/Orders/PageController.php @@ -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' ) ); } /** @@ -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. *