'WooCommerce - output product featured image vs output variation image

Woocommerce

Please help me understand why my first code snippet outputs the featured product image, while the second code snippet outputs the individual variation image.

I want to output the variation image (using version 2) - but I was also reading that get_product() is now deprecated and that is what my code uses.

//This code, below, outputs the featured product image

$product_id = $item->get_product_id();

$_product = wc_get_product( $product_id );

$thumbnail = $_product->get_image();

$image = '<div class="ts-product-image" style="width: 52px; height: 45px; display: inline-block; padding-right: 7px; vertical-align: middle;">'

. $thumbnail .

'</div>';

return $image . $name;

//This code, below, outputs the variation image.

$product = $item->get_product();
    
$thumbnail  = $product->get_image( );
    

 $image = '<div class="ts-product-image" style="width: 52px; height: 45px; display: inline-block; padding-right: 7px; vertical-align: middle;">'

. $thumbnail .

'</div>';


return $image . $name;

Thank you for any help explaining the difference here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source