How To Display Product Image In WooCommerce Order Emails

geekerhub

Updated on:

WooCommerce order emails

In WooCommerce, you can display product images in WooCommerce order emails by hooking into the email template and adding the appropriate code to display the image. Here’s one way you can do it:

  1. Locate the email template file you want to edit. The email template files can be found in the woocommerce/templates/emails/ directory of your theme. For example, the template for the new order email is located at woocommerce/templates/emails/admin-new-order.php.
  2. Add the following code to the appropriate place in the email template file:

 

 
 
 
Copy Code
<?php
foreach ( $items as $item_id => $item ) {
    $product = $item->get_product();
    $image = wp_get_attachment_image_src( $product->get_image_id() );
    echo '<img src="' . $image[0] . '" />';
}
?>

This code iterates through each item in the order, retrieves the associated product, and then gets the URL for the product’s image. The wp_get_attachment_image_src function takes the image ID as an argument, and returns an array containing the URL, width, and height of the image. You can use any of these elements as you need.

  1. Save the changes you’ve made to the email template file and upload it to your website.

Please keep in mind that this is just an example and it is possible that the email template files for different email types may vary, thus you will have to identify the correct location of the code. Also, the image size you are getting may not be the size that you want, this can be changed by adding the parameters of the size that you want on the wp_get_attachment_image_src() function.

Leave a Comment