Automattic\WooCommerce\Admin\Features\Navigation
Screen::is_woocommerce_page()
Check if we're on a WooCommerce page
Method of the class: Screen{}
No Hooks.
Return
true|false
.
Usage
$result = Screen::is_woocommerce_page();
Screen::is_woocommerce_page() Screen::is woocommerce page code WC 8.7.0
public static function is_woocommerce_page() { global $pagenow; // Get taxonomy if on a taxonomy screen. $taxonomy = ''; if ( in_array( $pagenow, array( 'edit-tags.php', 'term.php' ), true ) ) { if ( isset( $_GET['taxonomy'] ) ) { // phpcs:ignore CSRF ok. $taxonomy = sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) ); // phpcs:ignore CSRF ok. } } $taxonomies = self::get_taxonomies(); // Get post type if on a post screen. $post_type = ''; if ( in_array( $pagenow, array( 'edit.php', 'post.php', 'post-new.php' ), true ) ) { if ( isset( $_GET['post'] ) ) { // phpcs:ignore CSRF ok. $post_type = get_post_type( (int) $_GET['post'] ); // phpcs:ignore CSRF ok. } elseif ( isset( $_GET['post_type'] ) ) { // phpcs:ignore CSRF ok. $post_type = sanitize_text_field( wp_unslash( $_GET['post_type'] ) ); // phpcs:ignore CSRF ok. } } $post_types = self::get_post_types(); // Get current screen ID. $current_screen = get_current_screen(); $screen_ids = self::get_screen_ids(); $current_screen_id = $current_screen ? $current_screen->id : null; if ( in_array( $post_type, $post_types, true ) || in_array( $taxonomy, $taxonomies, true ) || self::is_woocommerce_core_taxonomy( $taxonomy ) || in_array( $current_screen_id, $screen_ids, true ) ) { return true; } return false; }