Desmond Lambkin
Desmond Lambkin

Reputation: 69

Displaying main product image from Woocommerce with a custom plugin

Hi I'm trying to create a custom plugin that will display the main product image from Woocommerce plugin. I want to use shortcode. How do I go about doing this? This is what I had and it didn't work. I've also found different suggestions. I will share everything below

add_shortcode( 'product_image', 'bbloomer_product_image_shortcode' );

    function bbloomer_product_reviews_shortcode() {    
       return woocommerce_get_product_thumbnail();
    }

<?php
$gallery_shortcode = '[gallery id="' .intval($post->$post_parent).'"]';
print apply_filters('the_content', $gallery_shortcode);
?>

These are what I found/were suggested to me before

Upvotes: 1

Views: 717

Answers (1)

Younes Bennour
Younes Bennour

Reputation: 759

try this:

$featured_image = wp_get_attachment_url( get_post_thumbnail_id($product_id)); 

Upvotes: 1

Related Questions