title: Get Woocommerce product category image url
body: <p>I have used the code following to get the thumbnail URL of a Woocommerce product category but it only outputs just the <code>&lt;img&gt;</code> tag with <code>src="unknown"</code>.</p>
  
  <pre><code>$cat_slug = t-shirts;
  $thumbnail_id = get_woocommerce_term_meta( $cat_slug, 'thumbnail_id', true );
  $image = wp_get_attachment_url( $thumbnail_id );
  echo '&lt;img src="'.$image.'" alt="" width="50" height="50" /&gt;'; 
  </code></pre>
  
  <p>What is the best approach to make it work?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>In the second call for thumbnail for the jean category it just outputs <code>&lt;img src(unknown) alt="" width="50" height="50" /&gt;</code>. </p>
  
  <pre><code>&lt;div class="list-item"&gt;
      &lt;div class="item-img"&gt;
  
          &lt;?php
  
          $term_slug    = 't-shirts';
          $taxonomy     = "product_cat";
          $term_id      = get_term_by( 'slug', $term_slug, $taxonomy )-&gt;term_id;
          $thumbnail_id = get_woocommerce_term_meta( $term_id, 'thumbnail_id', true );
          $image        = wp_get_attachment_url( $thumbnail_id );
  
          echo '&lt;img src="'.$image.'" alt="" width="50" height="50" /&gt;';
  
          ?&gt;
  
  &lt;/div&gt;
  
  &lt;a href="#"&gt;
      &lt;div class="item-name"&gt;
          &lt;?php if( $term = get_term_by('slug', 't-shirts', 'product_cat') ) echo $term-&gt;name;?&gt;
      &lt;/div&gt;
  &lt;/a&gt;
  
  &lt;/div&gt;
  
  &lt;div class="list-item"&gt;
      &lt;div class="item-img"&gt;
  
          &lt;?php
  
          $term_slug    = 'jeans';
          $taxonomy     = "product_cat";
          $term_id      = get_term_by( 'slug', $term_slug, $taxonomy )-&gt;term_id;
          $thumbnail_id = get_woocommerce_term_meta( $term_id, 'thumbnail_id', true );
          $image        = wp_get_attachment_url( $thumbnail_id );
  
          echo '&lt;img src="'.$image.'" alt="" width="50" height="50" /&gt;';
  
          ?&gt;
  
  &lt;/div&gt;
  
  &lt;a href="#"&gt;
      &lt;div class="item-name"&gt;
      &lt;?php if( $term = get_term_by('slug', 'jeans', 'product_cat') ) echo $term-&gt;name;?&gt;
      &lt;/div&gt;
  &lt;/a&gt;
  
  &lt;/div&gt;
  </code></pre>