doqrt26664 2015-05-28 15:38
浏览 61
已采纳

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?

  • 写回答

1条回答 默认 最新

  • dongyipa0028 2015-06-02 09:44
    关注

    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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向