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

I am trying to use is_category in woocommerce.php which does not work. I want to print the name on the page.

IF the page is a category page, then woocommerce_page_title() is printed, and if the page is a product, then print the_title() .

And the code that I use in woocommerce.php is:

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

But in each case, it prints the_title() . I think is_category() does not work for woocommerce.

Or Can anyone tell me how woocommerce does this to print category and product names?

Any help would be appreciated.

+6
source share
2 answers

you should use

 is_product_category() 

instead

 is_category() 
+21
source

Try creating the archive-product.php file in theme templates.

I usually copy the folder that is in the woocommerce folder and adds the range with the text β€œtest” to the one I create, so I see that it works.

-2
source

Source: https://habr.com/ru/post/972747/


All Articles