Woocommerce

How To Check Current Page Is A Product Category

Here we will learn about how to check current page is a product category.

There is two way to check page is a product category.

We will also find categories with certain IDs, slugs, and names.

1. is_product_category():

The WooCommerce product taxonomy is ‘product_cat’.

Let’s see WooCommerce conditional tags.

  • is_product_category() – returns true, every product category archive page.
  • is_product_category( $category ) – if you check product category.

Examples:

<?php
if( is_product_category() ) {
  // do something here...
} else {
  // do something here...
}
?>

It is also possible to pass multiple categories and slugs.

<?php
if( is_product_category( array( 3, 5, 9 ) ) ) {
  //  product categories with ID = 3 or 5 or 9
  // do something here...
} elseif( is_product_category( 'bmw' ) ) {
  // product categories with slug or title "bmw"
  // do something here...
} else {
  // do something here...
}
?>

2. is_tax( ‘product_cat’ ):

This function is similler like is_product_category().

Examples like same as above:

<?php
if( is_tax( 'product_cat', array( 3, 5, 9 ) ) ) {
  // do something here... 
} elseif( is_tax( 'product_cat', 'bmw' ) ) {
  // do something here...
} else {
  // do something here...
}
?>

 

 

Rahul Prajapat

I’m Rahul Prajapat. I’m a WordPress developer and Author at TheCodeHubs. I have good skill of Html, CSS, JQuery, SQL, Web API, PSD to HTML/PSD to WordPress, WordPress Theme/Plugin Customization, create or modify short code, customize visual composer short code or integrate new short code with visual composer, can create custom metabox for any post type in WordPress admin.

Share
Published by
Rahul Prajapat

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago