title: Wordpress WooCommerce display nested product category for individual product
body: <p>I have a Wordpress WooCommerce site that sells car parts. For each part (product) I have created unique Product Categories that I can assign to the part. So e.g. a headlight (part) can be from a 3-Door 1999 Blue Alfa Romeo 156 1.1 Petrol Manual.</p>
  
  <p>On the individual product page I want to display a nested list of only the Product Categories associated with THIS part. So when I tag a part I will have a nested view like the image below.
  <img src="https://i.stack.imgur.com/7eKOA.png" alt="enter image description here"></p>
  
  <p>However, my current code below the second image displays all Product Categories that has a part associated with it including THIS part. As can be seen in the second image below I have many other parts assigned to other car Makes and they are all displayed for THIS part. I only want THIS part to display Product Categories associated with THIS part. So under Make it should only display Alfa Romeo - not all the other Product Categories that has parts in them regardless if they are tagged in THIS part.
  <img src="https://i.stack.imgur.com/AVnBb.png" alt="enter image description here"></p>
  
  <p>Can anyone please help? </p>
  
  <p>Current code</p>
  
  <pre><code>&lt;?php 
      $woocCategoryTerms = get_terms('product_cat', array(
          'order'        =&gt; 'ASC',
          'hide_empty'   =&gt; true,  // (boolean) 
          'parent'       =&gt; 0,     // (integer) Get direct children of this term (only terms whose explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string.
          'hierarchical' =&gt; true,  // (boolean) Whether to include terms that have non-empty descendants (even if 'hide_empty' is set to true).
          ));    
  
      foreach($woocCategoryTerms as $wooCategoryTerm) : 
  ?&gt;
          &lt;ul&gt;
              &lt;li&gt;
                  &lt;a href="&lt;?php echo get_term_link( $wooCategoryTerm -&gt; slug, $wooCategoryTerm -&gt; taxonomy ); ?&gt;"&gt;
                      &lt;?php 
                          echo $wooCategoryTerm -&gt; name; 
                      ?&gt;
                  &lt;/a&gt;
                  &lt;ul class="wsubcategs"&gt;
                      &lt;?php
                          $wooSubArgs = array(
                              'hierarchical' =&gt; true,
                              'hide_empty' =&gt; true,
                              'parent' =&gt; $wooCategoryTerm -&gt; term_id,
                              'taxonomy' =&gt; 'product_cat'
                          );
  
                          $wooSubCategories = get_categories($wooSubArgs);
  
                          foreach ($wooSubCategories as $wooSubCategory):
                      ?&gt;
                              &lt;li&gt;
                                  &lt;a href="&lt;?php echo get_term_link( $wooSubCategory -&gt; slug, $wooSubCategory -&gt; taxonomy );?&gt;"&gt;
                                      &lt;?php 
                                          echo $wooSubCategory -&gt; name;
                                      ?&gt;
                                  &lt;/a&gt;
                              &lt;/li&gt;
                              &lt;?php
                          endforeach;
                              ?&gt;  
                  &lt;/ul&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
          &lt;?php 
      endforeach; 
          ?&gt;
  </code></pre>