Automattic\WooCommerce\Admin
WCAdminHelper::is_current_page_store_page
Check if the current page is a store page.
This should only be called when WP has has set up the query, typically during or after the parse_query or template_redirect action hooks.
Method of the class: WCAdminHelper{}
Hooks from the method
Returns
true|false.
Usage
$result = WCAdminHelper::is_current_page_store_page();
WCAdminHelper::is_current_page_store_page() WCAdminHelper::is current page store page code WC 10.5.0
public static function is_current_page_store_page() {
// WC store pages.
$store_pages = array(
'shop' => wc_get_page_id( 'shop' ),
'cart' => wc_get_page_id( 'cart' ),
'checkout' => wc_get_page_id( 'checkout' ),
'terms' => wc_terms_and_conditions_page_id(),
'coming_soon' => wc_get_page_id( 'coming_soon' ),
);
/**
* Filter the store pages array to check if a URL is a store page.
*
* @since 8.8.0
* @param array $store_pages The store pages array. The keys are the page slugs and the values are the page IDs.
*/
$store_pages = apply_filters( 'woocommerce_store_pages', $store_pages );
foreach ( $store_pages as $page_slug => $page_id ) {
if ( $page_id > 0 && is_page( $page_id ) ) {
return true;
}
}
// Product archive page.
if ( is_post_type_archive( 'product' ) ) {
return true;
}
// Product page.
if ( is_singular( 'product' ) ) {
return true;
}
// Product taxonomy page (e.g. Product Category, Product Tag, etc.).
if ( is_product_taxonomy() ) {
return true;
}
global $wp;
$url = self::get_url_from_wp( $wp );
/**
* Filter if a URL is a store page.
*
* @since 9.3.0
* @param bool $is_store_page Whether or not the URL is a store page.
* @param string $url URL to check.
*/
$is_store_page = apply_filters( 'woocommerce_is_extension_store_page', false, $url );
return filter_var( $is_store_page, FILTER_VALIDATE_BOOL );
}