In WooCommerce, I am trying to get all child product category terms from the parent term id of the current product category with the code below:
$category = get_queried_object();
$category_parent_id = $category->parent;
$category_test = get_terms( ['taxonomy' => 'product_cat', 'hide_empty' => false] );
The variable $category_parent_id
returns the parent product category id and $category_test
returns all product category terms
I'm trying to return all child product categories using the parent product category term id retrieved from $category->parent
Logically I tried:
$category_test = $category_parent_id->get_terms( ['taxonomy' => 'product_cat', 'hide_empty' => false] );
and
$category_test = $category->parent->get_terms( ['taxonomy' => 'product_cat', 'hide_empty' => false] );
But this didn't give me back all child categories of the current parent category. Anyone have any idea if and if so how this can be achieved?