title: Turn Woocommerce category ID into slug function
body: <p>I am looking for a function to convert the woocommerce category id into a category slug for a breadcrumb link. </p>
  
  <p>The following loop pulls the upper most product category ID for product pages. This is necessary because some of my products have 4 or 5 levels of hierarchy. </p>
  
  <p>This is working fine. </p>
  
  <pre><code>$prod_terms = get_the_terms( $post-&gt;ID, 'product_cat' );
  
      foreach ($prod_terms as $prod_term) {
  
          // gets product cat id
          $product_cat_id = $prod_term-&gt;term_id;
  
          // gets an array of all parent category levels
          $product_parent_categories_all_hierachy = get_ancestors( $product_cat_id, 'product_cat' );  
  
          // This cuts the array and extracts the last set in the array
          $last_parent_cat = array_slice($product_parent_categories_all_hierachy, -1, 1, true);
          foreach($last_parent_cat as $last_parent_cat_value){
       }
      }  
  </code></pre>
  
  <p>At this point <code>echo $last_parent_cat_value;</code> would give you the ID of the highest category. </p>
  
  <p>In order to turn this into a breadcrumb link I need to pull the category name. so...</p>
  
  <pre><code>        // This function turns Category Ids produced by the foreach loop above into Names
          function woocommerceCategoryName($id){
              $term = get_term( $id, 'product_cat' );
              return $term-&gt;name;        
          }
  </code></pre>
  
  <p>Now all I need is the slug to complete the link. so...</p>
  
  <pre><code>        //this function gets the category slug from the category id
          function get_cat_slug($cat_id) {
              $cat_id = (int) $cat_id;
              $category = &amp;get_category($cat_id);
              return $category-&gt;slug;
          }
  </code></pre>
  
  <p>but when I <code>echo</code></p>
  
  <pre><code>echo '&lt;a href="' . home_url() . '/product-category/' . get_cat_slug($last_parent_cat_value) . '/"&gt;' . woocommerceCategoryName($last_parent_cat_value) . '&lt;/a&gt;';
  </code></pre>
  
  <p>My Name function is working but my slug function is not. </p>
  
  <p>Can anyone shine any light into my error?</p>
  
  <p>when I <code>inspect element</code> on the front end here is my generated html...</p>
  
  <pre><code>&lt;a href="http://home.com/product-category//"&gt;Sports&lt;/a&gt;
  </code></pre>
  
  <p>Could I try and use the Name to generate the slug?</p>
  
  <p>Thanks for reading. </p>