WooCommerce - 检查品牌页面

I'm using WooCommerce on our site along with their Brands add-on to be able to group products together by brand - I know WooCommerce has it's own built in selection of hooks and filters but I want to write a function that checks if I'm on a Brand page or not because as far as I can tell it piggybacks WooCommerce post types to display the information.

I have used get_post_type() on both a normal WooCommerce category and product page, and also when I'm on a Brand page but all three come up with the custom post type of product. I know that the Brands plug-in uses a custom taxonomy of product_brand somewhere but I'm not sure how I can write a query to check if the page I'm on has this taxonomy.

If I run the following query…

$terms = get_terms( 'product_brand');

print_r($terms);

I get all of the brands that we have setup showing on the page.

Can anyone point me in the right direction?

I managed to find a solution to this problem using the is_tax() function that Wordpress provides for using on custom taxonomy archives.

Here's my code to check if I'm on a brand page or not. Have tested and appears to be working fine.

function is_brand_page_check() {
    if (is_tax( 'product_brand' )) {
        echo 'This is a product brand page';
    } else {
        echo 'This is NOT a product brand page';
    }
}
add_action('woocommerce_before_shop_loop', 'is_brand_page_check');