title: WooCommerce display product categories in product title
body: <p>I have a Wordpress (version 4.2.2) eCommerce site running WooCommerce (version 2.3.8).</p>
  
  <p>On my individual product page I wish to set the title of the product to also include the custom categories I have created in WooCommerce and that this product belongs to.</p>
  
  <p>I find the following file (wp-content/themes/mytheme/woocommerce/single-product/title.php) that relates to the title of the individual product and edit it as below to try and include the categories that this product belongs to in the title as well.</p>
  
  <p>With the code below I manage to display the categories, but the problem is that I am displaying ALL categories, and not just the categories that this product belongs to.</p>
  
  <p>How do I limit the categories returned to only the categories that the product belongs to please?</p>
  
  <pre><code>&lt;?php
  if ( ! defined( 'ABSPATH' ) ) 
      exit; // Exit if accessed directly
  ?&gt;
  
  &lt;!-- Original Product Title START --&gt;
  &lt;h1 itemprop="name" class="product-title entry-title"&gt;
      &lt;?php the_title(); ?&gt;
  &lt;/h1&gt;
  &lt;!-- Original Product Title END --&gt;
  
  
  &lt;!-- New Product Title START --&gt;
  &lt;h1 itemprop="name" class="product-title entry-title"&gt;
      &lt;?php
          $taxonomy     = 'product_cat';
          $orderby      = 'name';  
          $show_count   = 0;      // 1 for yes, 0 for no
          $pad_counts   = 0;      // 1 for yes, 0 for no
          $hierarchical = 1;      // 1 for yes, 0 for no  
          $title        = '';  
          $empty        = 0;
          $args = array(
              'taxonomy'     =&gt; $taxonomy,
              'orderby'      =&gt; $orderby,
              'show_count'   =&gt; $show_count,
              'pad_counts'   =&gt; $pad_counts,
              'hierarchical' =&gt; $hierarchical,
              'title_li'     =&gt; $title,
              'hide_empty'   =&gt; $empty
          );
      ?&gt;
  
      &lt;?php 
          $all_categories = get_categories( $args );
  
          foreach ($all_categories as $cat) 
          {
              if($cat-&gt;category_parent == 0) 
              {
                  $category_id = $cat-&gt;term_id;
      ?&gt;      
  
      &lt;?php       
          echo '&lt;br /&gt;&lt;a href="'. get_term_link($cat-&gt;slug, 'product_cat') .'"&gt;'. $cat-&gt;name .'&lt;/a&gt;'; 
      ?&gt;
  
      &lt;?php
          $args2 = array(
              'taxonomy'     =&gt; $taxonomy,
              'child_of'     =&gt; 0,
              'parent'       =&gt; $category_id,
              'orderby'      =&gt; $orderby,
              'show_count'   =&gt; $show_count,
              'pad_counts'   =&gt; $pad_counts,
              'hierarchical' =&gt; $hierarchical,
              'title_li'     =&gt; $title,
              'hide_empty'   =&gt; $empty
          );
  
          $sub_cats = get_categories( $args2 );
  
          if($sub_cats) 
          {
              foreach($sub_cats as $sub_category) 
              {
                  echo  '&lt;br/&gt;&lt;a href="'. get_term_link($sub_category-&gt;slug, 'product_cat') .'"&gt;'. $sub_category-&gt;name .'&lt;/a&gt;';
                  echo apply_filters( 'woocommerce_subcategory_count_html', ' &lt;span class="cat-count"&gt;' . $sub_category-&gt;count . '&lt;/span&gt;', $category );
              }
          }
      ?&gt;
  
      &lt;?php 
              }     
          }
      ?&gt;
  &lt;/h1&gt;
  &lt;!-- New Product Title END --&gt;
  </code></pre>