title: List product categories hierarchy from a product id in Woocommerce
body: <p>I have a products that can be in multiple categories, example take a look at the following strings:</p>
  
  <ul>
  <li>Cat1>Product1</li>
  <li>Cat1>Product2</li>
  <li>Cat2>subcat1>Product1</li>
  <li>Cat3>subcat1>subcat2>Product1</li>
  </ul>
  
  <p>In woocommerce, if I have a productid, I can do the following:</p>
  
  <pre><code>    function alg_product_categories_names2( $atts ) {
      $product_cats = get_the_terms( $this-&gt;get_product_or_variation_parent_id( $this-&gt;the_product ), 'product_cat' );
      $cats = array();
  
      $termstest= '';
      if ( ! empty( $product_cats ) &amp;&amp; is_array( $product_cats ) ) {
          foreach ( $product_cats as $product_cat ) {             
              if ( $term-&gt;parent == 0 ) { //if it's a parent category
                      $termstest .= ' PARENTCAT= '. $product_cat-&gt;name;
            }                             
          }
      }
  
      return htmlentities('&lt;categories_names&gt;'. $termstest .'&lt;/categories_names&gt;');
  }
  </code></pre>
  
  <p>But this simply returns all the parent categories for the product id.</p>
  
  <p>cat1, cat2, subcat1, Cat3, subcat2</p>
  
  <p>I'm having a hard time with this.  What I need is given a product id, build the list above - what should be returned is:</p>
  
  <p>"Cat1>Product1" | "Cat2>subcat1>Product1" | "Cat3>subcat1>subcat2>Product1"</p>
  
  <p>I basically need to rebuild each category path from the product id.</p>