woocommerce_get_product_subcategories()WC 1.0

Get (and cache) product subcategories.

Возвращает

Массив.

Использование

woocommerce_get_product_subcategories( $parent_id );
$parent_id(int)
Get subcategories of this ID.

Код woocommerce_get_product_subcategories() WC 8.7.0

function woocommerce_get_product_subcategories( $parent_id = 0 ) {
	$parent_id          = absint( $parent_id );
	$cache_key          = apply_filters( 'woocommerce_get_product_subcategories_cache_key', 'product-category-hierarchy-' . $parent_id, $parent_id );
	$product_categories = $cache_key ? wp_cache_get( $cache_key, 'product_cat' ) : false;

	if ( false === $product_categories ) {
		// NOTE: using child_of instead of parent - this is not ideal but due to a WP bug ( https://core.trac.wordpress.org/ticket/15626 ) pad_counts won't work.
		$product_categories = get_categories(
			apply_filters(
				'woocommerce_product_subcategories_args',
				array(
					'parent'       => $parent_id,
					'hide_empty'   => 0,
					'hierarchical' => 1,
					'taxonomy'     => 'product_cat',
					'pad_counts'   => 1,
				)
			)
		);

		if ( $cache_key ) {
			wp_cache_set( $cache_key, $product_categories, 'product_cat' );
		}
	}

	if ( apply_filters( 'woocommerce_product_subcategories_hide_empty', true ) ) {
		$product_categories = wp_list_filter( $product_categories, array( 'count' => 0 ), 'NOT' );
	}

	return $product_categories;
}