From 1e40699ed270750b44803edd489c8ff4579cdc0a Mon Sep 17 00:00:00 2001 From: Corey McKrill <916023+coreymckrill@users.noreply.github.com> Date: Tue, 23 May 2023 16:10:32 -0700 Subject: [PATCH] Add OrderUtil methods to check for specific order admin screens --- .../woocommerce/src/Utilities/OrderUtil.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/plugins/woocommerce/src/Utilities/OrderUtil.php b/plugins/woocommerce/src/Utilities/OrderUtil.php index 21775789852..cbc8ae51f7a 100644 --- a/plugins/woocommerce/src/Utilities/OrderUtil.php +++ b/plugins/woocommerce/src/Utilities/OrderUtil.php @@ -135,6 +135,39 @@ final class OrderUtil { return wc_get_container()->get( PageController::class )->get_new_page_url(); } + /** + * Check if the current admin screen is an order list table. + * + * @param string $order_type Optional. The order type to check for. Default shop_order. + * + * @return bool + */ + public static function is_order_list_table_screen( $order_type = 'shop_order' ) : bool { + return wc_get_container()->get( PageController::class )->is_order_screen( $order_type, 'list' ); + } + + /** + * Check if the current admin screen is for editing an order. + * + * @param string $order_type Optional. The order type to check for. Default shop_order. + * + * @return bool + */ + public static function is_order_edit_screen( $order_type = 'shop_order' ) : bool { + return wc_get_container()->get( PageController::class )->is_order_screen( $order_type, 'edit' ); + } + + /** + * Check if the current admin screen is adding a new order. + * + * @param string $order_type Optional. The order type to check for. Default shop_order. + * + * @return bool + */ + public static function is_new_order_screen( $order_type = 'shop_order' ) : bool { + return wc_get_container()->get( PageController::class )->is_order_screen( $order_type, 'new' ); + } + /** * Get the name of the database table that's currently in use for orders. *