如何检查网页是woocommerce中的类别还是产品?

问题描述:

我正在尝试在woocommerce.php中使用is_category,但该方法不起作用.我想根据页面打印标题.

I'm trying to use is_category in woocommerce.php which is not working. I want to print the title according the page.

如果页面是类别页面,则将打印woocommerce_page_title();如果页面是产品页面,则应打印the_title().

IF a page is category page then will print woocommerce_page_title() and if a page is product then should print the_title().

我在woocommerce.php中使用的代码是:

<?php if(is_category()){ ?>                       
    <h1 class="page-title"><?php woocommerce_page_title(); ?></h1> 
<?php }
else{
    the_title();
}
?>

但是在每种情况下它都在打印the_title().我认为is_category()不适用于woocommerce.

But in every case it is printing the_title() . I think is_category() is not working for woocommerce.

或者可以说出woocommerce如何打印类别和产品标题吗?

Or Can any one tell how woocommerce do it to print category and product title?

任何帮助将不胜感激.

您应该使用

is_product_category()

代替

is_category()