Skip to content
Advertisement

Display custom product image on WooCommerce email notifications

I am trying to modify the product images in the auto generated WooCommerce order e-mails. Note, I am trying to do this with hooks, rather than creating a modified e-mail template.

To start, I have a hidden input on the single product page. I have some JS that sets the ID of the image, which is based on the product’s colour (a custom attribute I made with ACF).

JavaScript

For reference, here’s what I’ve done to get this to work on the cart page:

JavaScript

That works fine, but I’m having difficulty replicating this in the order e-mail. So far I’ve come across the following. This shows images in the e-mail, but it’s the product’s featured image. Of note is the “show_image” key being set to true.

JavaScript

To modify the image, I found this filter, but I’m just having a difficult time figuring out what I need to do to replicate what I’ve done on the cart page. The closest I’ve got is having $item_data work, and I do see the product-col-img-id key in the var dump, though it’s in a protected object, which I’m not sure how to access. Even if I could access, I’m not sure how I could even set the image from here.

JavaScript

Advertisement

Answer

To get WooCommerce custom meta data, you can use WC_Data method get_meta().

Try the following instead to display your custom image on email notifications:

JavaScript

Code goes in functions.php file of the active child theme (or active theme). It should work.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement