Stack Exchange
wp_get_attachment_url not fetching URL?
the below code does not seem to return an image url at all, chrome inspector says source is unknown
  foreach ($subcategories as $subcategory) {
            $link = get_term_link( $subcategory->slug, $subcategory->taxonomy );
            $thumbnail_id = get_term_meta( $subcategory->term_id, 'thumbnail_id', true );
            $image= wp_get_attachment_url( $thumbnail_id );
            echo '<img src="' . $image . '" width="50" height="50" />';

Full Code
// Adding Child Category List to Main Category Display Grid

add_action('woocommerce_after_subcategory', 'woocommerce_subcats_from_parentcat_by_ID', 20);

function woocommerce_subcats_from_parentcat_by_ID($category) {
    $parent_category_ID = $category->term_id;
    $args = array(
        'hierarchical' => 1,
        'show_option_none' => '',
        'hide_empty' => 0, // Set to 0 to show empty categories and 1 to hide them
        'parent' => $parent_category_ID,
        'taxonomy' => 'product_cat'
    );
    $subcategories = get_categories($args);
    echo '<ul class="woo_subcategory_list">';
    foreach ($subcategories as $subcategory) {
        $link = get_term_link( $subcategory->slug, $subcategory->taxonomy );
        $thumbnail_id = get_term_meta( $subcategory->term_id, 'thumbnail_id', true );
        $image= wp_get_attachment_url( $thumbnail_id );
        echo '<img src="' . $image . '" width="50" height="50" />';
    }
    echo '</ul>';
}


then check like that:
$thumb_id = get_woocommerce_term_meta( $subcategory->term_id, 'thumbnail_id', true );
$term_img = wp_get_attachment_url(  $thumb_id );

and check like this
$meta = get_term_meta( $subcategory->term_id );
var_dump($meta);
$thumb_id = $meta['thumbnail_id'][0];
$term_img = wp_get_attachment_url(  $thumb_id );

and you also get like this
$thumbnail_id = get_term_meta( $subcategory->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );


Deprecated: get_woocommerce_term_meta is
deprecated
since version 3.6! Use get_term_meta instead

$thumb_id = get_woocommerce_term_meta( $subcategory->term_id, 'thumbnail_id', true ); $term_img = wp_get_attachment_url(  $thumb_id ); is not working

Then first please print $subcategory->term_id and check what id you get

seems to return the ids correctly

$thumb_id returns 0 though

please check all meta it's give thub id or not?

$meta = get_term_meta( $term_id ); ??? $term_id isnt declared?

Dean with this $subcategory->term_id

array(3) { ["order"]=> array(1) { [0]=> string(1) "0" } ["display_type"]=> array(1) { [0]=> string(0) "" } ["thumbnail_id"]=> array(1) { [0]=> string(1) "0" } } array(3) { ["order"]=> array(1) { [0]=> string(1) "0" } ["display_type"]=> array(1) { [0]=> string(0) "" } ["thumbnail_id"]=> array(1) { [0]=> string(1) "0" } }

Dean are you sure you set thumbnail for term. Because thumbnail_id is 0. please check in admin and you set thumbnail then check database entry.

I didn't set images but I thought it would have used the standard default image if no image assigned??

ah it works now that I added images, thank you! used your third edit for the answer
