wc_get_product_cat_ids( int $product_id )

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


Description Description


Parameters Parameters

$product_id

(Required) Product ID.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/wc-product-functions.php

function wc_get_product_cat_ids( $product_id ) {
	$product_cats = wc_get_product_term_ids( $product_id, 'product_cat' );

	foreach ( $product_cats as $product_cat ) {
		$product_cats = array_merge( $product_cats, get_ancestors( $product_cat, 'product_cat' ) );
	}

	return $product_cats;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.5.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.