Title: Variable Product Image
Last modified: July 24, 2022

---

# Variable Product Image

 *  Resolved [davidovic123](https://wordpress.org/support/users/davidovic123/)
 * (@davidovic123)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/variable-product-image-2/)
 * Hi,
 * I added the following snippet as recommended, but it seems that the code does
   not display the image for the product that has the variation attribute.
    It only
   works for the “Simple product”.
 *     ```
       function example_product_image( $product ) {    
           if( ( '' !== $product->get_id() ) && has_post_thumbnail( $product->get_id() ) ) {
                echo get_the_post_thumbnail( $product->get_id(), array( 40, 40 ), array( 'loading' => false ) );
           }
       }
       add_action( 'wcdn_order_item_before', 'example_product_image' );
       ```
   
 * Please,
 * How to make this snippet work for “Variable Product”?
    And, How to display a 
   description text next to the image, aligned vertically, and avoid that the image
   is surrounded by the text?
 * Thank you very much,
    -  This topic was modified 3 years, 10 months ago by [davidovic123](https://wordpress.org/support/users/davidovic123/).
    -  This topic was modified 3 years, 10 months ago by [davidovic123](https://wordpress.org/support/users/davidovic123/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Moksha Shah](https://wordpress.org/support/users/mokshasharmila13/)
 * (@mokshasharmila13)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/variable-product-image-2/#post-15855221)
 * Hi [@davidovic123](https://wordpress.org/support/users/davidovic123/),
 * For display the image for the product that has the variation attribute and will
   add short description below the image. please add the below code in your active
   theme’s functions.php file or using a plugin like Code Snippets:
 *     ```
       function add_product_image( $product_name, $item ) {
       	$product_id    = $item['product_id'];
       	$product_instance = wc_get_product($product_id);
           $product_short_description = $product_instance->get_short_description();   
       	$product_image = wp_get_attachment_image_src( get_post_thumbnail_id( $product_id ) );
       	?>
       	<img src="<?php echo esc_url( $product_image[0] ); ?>" width="50" height="50" >
       	<?php
       	echo '<br>'. $product_short_description;
       	echo '<br>' . $product_name;
       } add_filter( 'wcdn_order_item_name', 'add_product_image', 10, 2 );
       ```
   
 * Regards,
    Moksha.
 *  Thread Starter [davidovic123](https://wordpress.org/support/users/davidovic123/)
 * (@davidovic123)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/variable-product-image-2/#post-15855928)
 * Hi [@mokshasharmila13](https://wordpress.org/support/users/mokshasharmila13/),
 * Thanks for your reply & for the code snippet.
    It works.
 * Thank you very much for your support, Have a great day,
 *  [Moksha Shah](https://wordpress.org/support/users/mokshasharmila13/)
 * (@mokshasharmila13)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/variable-product-image-2/#post-15856121)
 * Hi [@davidovic123](https://wordpress.org/support/users/davidovic123/),
 * Good to know that your problem is resolved 🙂.
    It would be great if you can 
   give a review for the plugin & the support on [https://wordpress.org/support/plugin/woocommerce-delivery-notes/reviews/#new-post](https://wordpress.org/support/plugin/woocommerce-delivery-notes/reviews/#new-post).
   That would be very helpful.
 * Regards,
    Moksha.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Variable Product Image’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-delivery-notes/assets/icon-256x256.jpg?rev=2829362)
 * [Print Invoice & Delivery Notes for WooCommerce](https://wordpress.org/plugins/woocommerce-delivery-notes/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-delivery-notes/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-delivery-notes/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-delivery-notes/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-delivery-notes/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-delivery-notes/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Moksha Shah](https://wordpress.org/support/users/mokshasharmila13/)
 * Last activity: [3 years, 10 months ago](https://wordpress.org/support/topic/variable-product-image-2/#post-15856121)
 * Status: resolved