When WooCommerce store sends order emails to your customers, by default, it only includes the product name in the order items table within the email. However, this isn’t the only data that WooCommerce could include in the order items table of the emails. By default, these data items are “turned off”. WooCommerce can include relevant product information such as SKU and product image. The process is very simple and involves switching the defaults for these pieces of data “on”. This allows WooCommerce to add more information in the emails.
Add Product Images and/or SKU to WooCommerce Order Emails
With WooCommerce , you can easily include product images to the order items within the shop’s transactional emails. Turning these data items “on” could be done using a filter.
This filter passes in all of the default values for the email order items table. By default, SKUs, purchase notes, images, and download links are all set to false (“off”). WooCommerce conditionally handles turning some of these data items on itself, such as download links when download access needs to be granted. However, SKUs and images need to be turned “on” manually.
I will start by enabling product images within the email order items template. I will pass the data into the filter and then return it. However, I will change the show_image value to true instead with this snippet (in a custom plugin or functions.php):
function cw_add_wc_order_email_images( $output, $order ) { static $run = 0; if ( $run ) { return $output; } $args = array( 'order' => $order, 'items' => $order->get_items(), 'show_download_links' => $show_download_links, 'show_sku' => $show_sku, 'show_purchase_note' => $show_purchase_note, 'show_image' => true, 'image_size' => array( 100, 50 ) ); $run++; return $order->email_order_items_table( $args ); } add_filter( 'woocommerce_email_order_items_table', 'cw_add_wc_order_email_images' );
This snippet could also be edited to change the image size. Rather than including $image_size for this value, I can pass in an array of sizes. The first number in this array will be the width and the second number is the height.
Let’s change the image size
'image_size' => $image_size To 'image_size' => array( 100, 50 )
Add SKU Information to WooCommerce Emails
Product SKUs can be easily turned on within the emails using the same snippet. To do this, you need to change:
'show_sku' => $show_sku, To 'show_sku' => true,
As a final note on adding SKUs to emails, I do not prefer the current position (inline with the product name. To change this:
function cw_edit_order_item_name( $name ) { return $name . '<br />'; } add_filter( 'woocommerce_order_item_name', 'cw_edit_order_item_name' );
Conclusion
In this article, I discussed how to enable the addition of product images and SKU information about the products in the WooCommerce emails. The process is really simple and could be accomplished through simple code snippets. If you need any further clarification or would like to contribute to the discussion, do leave a comment below.
Owais Alam
is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at [email protected]