wc_get_product_cat_ids

Get all product cats for a product by ID, including hierarchy.

Description

(array) wc_get_product_cat_ids( (int) $product_id ); 

Returns (array)

Parameters (1)

0. $product_id (int)
The product id.

Usage

  1. if ( !function_exists( 'wc_get_product_cat_ids' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-product-functions.php'; 
  3.  
  4. // The product id. 
  5. $product_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_get_product_cat_ids($product_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-product-functions.php  
  1. function wc_get_product_cat_ids( $product_id ) { 
  2. $product_cats = wc_get_product_term_ids( $product_id, 'product_cat' ); 
  3.  
  4. foreach ( $product_cats as $product_cat ) { 
  5. $product_cats = array_merge( $product_cats, get_ancestors( $product_cat, 'product_cat' ) ); 
  6.  
  7. return $product_cats;