I’m selling multiple products, each with 2 variations that will each need to have a custom bit of text (with with URLs embedded) in the Completed email. Lots of custom emails: per product and variation. I’ve found many options for functions.php but they are all from many years and woo versions ago.
The very popular "Woo Custom Emails Per Product" plugin does not have a per-variation function. I do not want to make each variation its own product (and could therefore use that plugin) since I want a single product page for each, where the patron can select the variation they want.
So I decided the best way to add the info for each variation is in the "Description" field for the variation.
Here’s where I would like it go, above what I believe is the woocommerce_email_order_items_table:
screen grab of email showing where text should go
I tried adding this to functions.php but it’s from 2015 and is for "processing" not "completed" emails:
add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );
function render_product_description($item_id, $item, $order){
$_product = $order->get_product_from_item( $item );
echo "<br>" . $_product->post->post_content;
}
add_action('woocommerce_order_item_meta_end', 'render_product_description',10,3);
I’ve tried this, but it’s from years ago and did not accomplish what I need:
Add the product description to WooCommerce email notifications
This is close: Add Custom Product Field in WooCommerce 'Order Completed' Emails but not quite what I want, because there is not a custom field specific to each variation; it seems the only thing custom to each variation is "Description."
I’d like to find a way to edit the email template, as I think that would be the ideal way to go here. If it can simply list the Description contents for each item’s variation ordered, I can format that text to be self-explanatory for the patron, and then the order summary box (with Product/Quantity/Price) will stay clean and just list the items.
This is a test page I set up: https://www.chambermusicpittsburgh.org/concerts-and-tickets-new-store/. Only the Escher and Dover product has the variables, with a tester phrase and URL in the Description for the weblink (which will pop down if you choose that option, but which I will eventually hide here with CSS but I’ve left it for testing).
I feel like adding the variation Description to the email should be super straightforward/simple, and maybe I’m not experienced enough or not looking in the right place, but that particular piece of data seems extremely hard to hook into and display in the Order Confirmed email.
Thanks!
2
Answers
To add custom content to the email template at this point:
You can use the
woocommerce_email_before_order_table
hook. See here for more information.The following function will get the descriptions of each ordered product (if the description is not empty).
The code has been tested and works. Add it to your active theme’s functions.php.
This works but added the description in both the processing and the completed mail and admin mails. There seems to something wrong with the status check
$email->id == 'customer_completed_order'
. I added$status = $order->get_status();
and changed it to look for$status == "completed"
instead. It works for me, but please add your thoughts or comments if this is a good way.