简体   繁体   中英

How to check if a page is category or product in woocommerce?

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

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

And the code I am using in woocommerce.php is:

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

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

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

Any help will be appreciated.

you should use

is_product_category()

instead of

is_category()

Try creating a archive-product.php file within the theme templates.

I usually copy the one that is in the woocommerce folder and add a span with "test" text to the one I create so I can see it's working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM