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?

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