From 016d9484dc59ebb6c35aa8b43804683af83b7e36 Mon Sep 17 00:00:00 2001 From: Corey McKrill <916023+coreymckrill@users.noreply.github.com> Date: Wed, 7 Jun 2023 09:28:10 -0700 Subject: [PATCH] HPOS: Add descriptive document titles to HPOS order admin screens (#38617) * Set the Orders admin page titles * Tweak edit order title, translator messages * Add changelog file * phpcs cleanup --- .../changelog/update-order-admin-page-titles | 4 ++ .../Internal/Admin/Orders/PageController.php | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 plugins/woocommerce/changelog/update-order-admin-page-titles 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. *