Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 422
user3777827 Avatar asked Jul 24 '14 06:07

user3777827


People also ask

Is WooCommerce a product category page?

What is a WooCommerce Category Page? WooCommerce allows users to list products from a specific category or subcategory in a grid-style layout. By default, large product images with their name, price, and purchase options will be displayed.

How do I find the category of a WordPress page?

I have found the way to do it by checking if $cat_id is available or not on that page by the following. $cat_id = get_query_var('cat'); Now we can check if $cat_id is available then it is a category page otherwise it is not.

How do I show category description in WooCommerce?

Show the WooCommerce category descriptionCopy the template file from wp-content/plugins/woocommerce/templates/archive-product. php to wp-content/themes/[your-child-theme]/woocommerce/archive-product. php. Now we can edit that without changing any plugin files directly (which could get replaced on the next update).


1 Answers

you should use

is_product_category()

instead of

is_category()
like image 117
Shah Rukh Avatar answered Sep 28 '22 03:09

Shah Rukh