How to get woocommerce product subcategory
Today we talk about how to get a woocommerce product subcategory from the main product category programmatically. This example covered the product category. This example only shows how to get a subcategory from the parent category. So let’s start with our example.
The following example will get the product subcategories.
$parent = 1;
$childArg = array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'parent' => $parent
);
$childCats = get_terms( $childArg );
foreach ($childCats as $childCat)
{
echo $childCat->name;
}
$childArg = array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'parent' => $parent
);
$childCats = get_terms( $childArg );
foreach ($childCats as $childCat)
{
echo $childCat->name;
}