WooCommerce get category slug - Undefined property notice with a function
<p>I use this function to convert the woocommerce category id into a category slug</p>

<pre><code>function woocommerceCategorySlug($id){
    $term = get_term( $id, 'product_cat' );
    return $term-&gt;slug;       
}
</code></pre>

<p>This is working, but the problem is that i'm getting a notice </p>

<blockquote>
<pre><code>Notice: Undefined property: WP_Error::$slug 
</code></pre>
</blockquote>

<p>Is there a way to avoid this notice?</p>