WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: WooCommerce] Product Category Thumbnail not displaying (4 posts)

  1. dustylavender
    Member
    Posted 2 years ago #

    The code on taxonomy-product_cat.php (below) is not displaying the product category thumbnail. Side note: I added a new size "brand_thumbnail" to my theme, but it wasn't working prior to using "shop_thumbnail" or "shop_category".

    <?php $term = get_term_by( 'slug', get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy']); ?>
    
    <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'brand_thumbnail'); else echo '<img src="'.$woocommerce->plugin_url().'/assets/images/placeholder.png" alt="Placeholder" width="310px" height="265px" />'; ?>

    Is there something wrong with my post_thumbnail ($loop.......)?

  2. tongny
    Member
    Posted 2 years ago #

    I also face this problem, and now not yet solve

  3. virtualpudding
    Member
    Posted 2 years ago #

    I've also been having problems with this.

    I ended up using this for now (which works) but i'm looking into alt method.

    global $wp_query;
    $cat = $wp_query->get_queried_object();
    $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
    $image = wp_get_attachment_url( $thumbnail_id );
    echo '<img src="' . $image . '" width="200px" height="200px" />';
  4. Wellton
    Member
    Posted 1 year ago #

    To avoid Safari showing an empty box at the size of the thumbnail when there is no thumbnail, do this isnstead:

    global $wp_query;
    $cat = $wp_query->get_queried_object();
    $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
    $image = wp_get_attachment_url( $thumbnail_id );
    echo wp_get_attachment_image( $thumbnail_id );

Topic Closed

This topic has been closed to new replies.

About this Topic