How to get featured image of a product in woocommerce

前端 未结 8 1226
梦毁少年i
梦毁少年i 2021-02-05 00:26

Please tell me where I am going wrong . Product featured image is not showing up.

   $args = array( \'post_type\' => \'product\', \'posts_per_page\' => 80,         


        
相关标签:
8条回答
  • 2021-02-05 00:39

    I got the solution . I tried this .

    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $loop->post->ID ), 'single-post-thumbnail' );?>
    
        <img src="<?php  echo $image[0]; ?>" data-id="<?php echo $loop->post->ID; ?>">
    
    0 讨论(0)
  • 2021-02-05 00:48

    I had the same problem and solved it by using the default woocommerce hook to display the product image.

    while ( $loop->have_posts() ) : $loop->the_post();
       echo woocommerce_get_product_thumbnail('woocommerce_full_size');
    endwhile;
    

    Available parameters:

    • woocommerce_thumbnail
    • woocommerce_full_size
    0 讨论(0)
  • 2021-02-05 00:50

    The answers here, are way too complex. Here's something I've recently used:

    <?php global $product; ?>
    <img src="<?php echo wp_get_attachment_url( $product->get_image_id() ); ?>" />
    

    Using wp_get_attachment_url() to display the

    0 讨论(0)
  • 2021-02-05 00:50

    In WC 3.0+ versions the image can get by below code.

    $image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $item->get_product_id() ), 'single-post-thumbnail' );
    echo $image_url[0]
    
    0 讨论(0)
  • 2021-02-05 00:51

    I did this and it works great

    <?php if ( has_post_thumbnail() ) { ?>
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
    <?php } ?>
    
    0 讨论(0)
  • 2021-02-05 00:53

    I would just use get_the_post_thumbnail_url() instead of get_the_post_thumbnail()

    <img src="<?php echo get_the_post_thumbnail_url($loop->post->ID); ?>" class="img-responsive" alt=""/>
    
    0 讨论(0)
提交回复
热议问题