title: How to get Categories from product id in single page
body: <p>I am trying to retrieve Related Categories from product id.
  Suppose I have categories like bellow.</p>
  
  <pre><code>iPhone (Parent Category)
    -iPhone 3 (sub)
    -iPhone 4 (sub)
    -iPhone 5 (sub)
    -iPhone 6 (sub)
  </code></pre>
  
  <p>if a Product : iPhone 4 Charger. (in iPhone 4 sub category)</p>
  
  <p>How can I retrieve all above categories by the product id (iPhone 4 Charger)
  as a list?</p>
  
  <p>I think Step may be == (get product id) --> (get category) --> (get parent category) --> (get category list of this parent category)</p>
  
  <p>I am trying below code</p>
  
  <pre><code>&lt;?php 
  $parent = get_category_parents( $cat, true, ' &amp;raquo; ' ); 
  echo $product-&gt;get_categories( ', ', '&lt;span&gt;' . _n( 'Category:', 'Categories:', sizeof( get_the_terms( $post-&gt;ID, 'product_cat' ) ), 'woocommerce' ) . ' ', '.&lt;/span&gt;' ); 
  ?&gt;
  </code></pre>