product list php id:

For my WC product pages, I need to add a class to the body tag so that I can perform some custom styling. Here’s the function I’m creating for this…
function my_add_woo_cat_class($classes) {

$wooCatIdForThisProduct = “?????”; //help!

// add ‘class-name’ to the $classes array
$classes[] = ‘my-woo-cat-id-‘ . $wooCatIdForThisProduct;
// return the $classes array
return $classes;

//If we’re showing a WC product page
if (is_product()) {
// Add specific CSS class by filter
…but how do I get the WooCommerce cat ID?

About Nilesh Raut

I am Nilesh,3+ years Exp of SEO, content writing, and keyword research. Also rocks it as a software dev with skills in OS, web dev, Flask, Python, C++, data structures, and algorithms. 3 on Leetcode, 5*on Hackerrank more platform.

Question is closed for new answers.
Nilesh Raut Selected answer as best July 20, 2023