id, self::hpos_order_page_ids(), true ) ) { return in_array( $action, array( 'edit', 'new' ), true ); } return 'shop_order' === $screen->id; } /** * Whether the current screen is the Orders list (HPOS or legacy). * * Safe outside wp-admin: returns false when there is no current screen. * * @since 1.0.0 * @return bool */ public static function is_order_list(): bool { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen ) { return false; } if ( in_array( $screen->id, self::hpos_order_page_ids(), true ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only routing check. $action = isset( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : ''; return ! in_array( $action, array( 'edit', 'new' ), true ); } return 'edit-shop_order' === $screen->id; } /** * Screen IDs of WooCommerce's HPOS Orders page (list and edit share one page). WooCommerce * names it `woocommerce_page_wc-orders`, or `admin_page_wc-orders` for users who can't see the * WooCommerce menu. * * @since 1.0.0 * @return string[] */ private static function hpos_order_page_ids() { $ids = array( 'woocommerce_page_wc-orders', 'admin_page_wc-orders' ); // wc_get_page_screen_id() only exists in wp-admin; never call it on front-end/CLI/REST requests. if ( is_admin() && function_exists( 'wc_get_page_screen_id' ) ) { $current = (string) wc_get_page_screen_id( 'shop-order' ); if ( str_ends_with( $current, '_page_wc-orders' ) && ! in_array( $current, $ids, true ) ) { $ids[] = $current; } } return $ids; } /** * Screen ID of the order edit screen for the active storage. * * @since 1.0.0 * @return string */ public static function order_screen_id() { if ( ! class_exists( OrderUtil::class ) || ! OrderUtil::custom_orders_table_usage_is_enabled() ) { return 'shop_order'; } // wc_get_page_screen_id() only exists in wp-admin; never call it on front-end/CLI/REST requests. return function_exists( 'wc_get_page_screen_id' ) ? wc_get_page_screen_id( 'shop-order' ) : 'woocommerce_page_wc-orders'; } }