-
-
Save bekarice/b270ebf7cd4fba56743f4170f05ec36f to your computer and use it in GitHub Desktop.
<?php // only copy this line if needed | |
/** | |
* Adds product images to the WooCommerce order emails table | |
* Uses WooCommerce 2.5 or newer | |
* | |
* @param string $output the buffered email order items content | |
* @param \WC_Order $order | |
* @return $output the updated output | |
*/ | |
function sww_add_images_woocommerce_emails( $output, $order ) { | |
// set a flag so we don't recursively call this filter | |
static $run = 0; | |
// if we've already run this filter, bail out | |
if ( $run ) { | |
return $output; | |
} | |
$args = array( | |
'show_image' => true, | |
'image_size' => array( 100, 100 ), | |
); | |
// increment our flag so we don't run again | |
$run++; | |
// if first run, give WooComm our updated table | |
return $order->email_order_items_table( $args ); | |
} | |
add_filter( 'woocommerce_email_order_items_table', 'sww_add_images_woocommerce_emails', 10, 2 ); |
Throw it in a plugin or in the themes functions.php :)
email_order_items_table is deprecated and should be replaced with wc_get_email_order_items
The WC_Order::email_order_items_table function is deprecated since version 3.0. Replace with wc_get_email_order_items
Tell me please. how to add this code in functions.php file
Updated code, perfectly working. Paste this code to the function.php file of your theme.
// Adds product image to WooCommerce order emails
function akash_add_image_to_wc_emails( $args ) {
$args['show_image'] = true;
$args['image_size'] = array( 100, 50 );
return $args;
}
add_filter( 'woocommerce_email_order_items_args', 'akash_add_image_to_wc_emails' );
Thank you.
$args'image_size'] = array( 100, 50 );
Should be
$args['image_size'] = array( 100, 50 );
But it works, thanks!
Hi,
How to make name of the product to be under the image. Maybe add some "br" оr something?
This sounds awesome! But there are no instructions on how to set it up. Do I:
a) add this code to the existing email-order-items.php ?
b) create a new php file with this code and somehow hook it email-order-items.php ?
c) something else?