woocommerce_get_product_subcategories( int $parent_id )
Get (and cache) product subcategories.
Description Description
Parameters Parameters
- $parent_id
-
(Required) Get subcategories of this ID.
Return Return
(array)
Source Source
File: includes/wc-template-functions.php
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; }