How can I include this "Downloads" section (attached) in the admin email? By default, WooCommerce only sends it to the customer, not the store owner.
I tried looking at articles that showed how to customize WooCommerce emails and I think that woocommerce_email_order_details
is the hook that I’m looking for. However, I am stuck with just this piece of information as I cannot find how to actually use this hook to change the contents of an email notification.
Furthermore, I also looked at the email templates included by WooCommerce: I noticed that both the Customer notification and the Admin notification have this line do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
It is identical in both, and I assume it behaves differently depending on whether or not $sent_to_admin
is True
; however again, I haven’t been able to find how I can use this to have the email include the Downloads section in both the customer and admin email.
Any advice?
3
Answers
Looking at Woocommerce code you can find in: wp-content/plugins/woocommerce/includes/class-wc-emails.php this piece of code:
Which leads exactly to what you think, $sent_to_admin is responsible for the download part to appear or not to appear.
If you want that to appear in the admin order email i think the easiest way to achieve this would be to do something like this:
do_action( ‘woocommerce_email_order_details’, $order, $sent_to_admin, $plain_text, $email );
to this:
This should make the difference
Download order template is loaded by using this function located at /wp-content/plugins/woocommerce/includes/class-wc-emails.php
as you can see, you need to make the conditions to be true. If all other conditions are true, then you just need to make the "$sent_to_admin" value to false. Which you can achieve by updating the following file located at
/wp-content/themes/your-theme/woocommerce/emails/admin-new-order.php
Replace
To
Here I have stored $sent_to_admin default value thinking you might have custom order meta or email footer section for admin only.
Although I have not tested this on any website, but I hope this will work fine.
This answer contains a solution, without overwriting template files
In includes/class-wc-emails.php we can find
As you can see the add_action contains a callback to the
order_downloads()
function.This function contains a condition
$show_downloads
, it must be true to show order downloads in a table. So should$sent_to_admin
be false, to meet your demand.So to answer your question. Without overwriting template files, use: