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;
  }

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!