I had asked this before but unfortunately I realized that the answer given did not work, so I am asking again:
I am trying to add some text to the customer-order-processing email from WooCommerce
, and it should ONLY be added in this particular email and ONLY if chosen payment method is Paypal
. I have come so far as the text is added, and only when Paypal is chosen as payment method, but the text is displayed in every email to the customer now, for example also in the order-completed email or customer-note email. I have the following:
add_action('woocommerce_email_before_order_table','add_order_email_instructions', 0, 2);
function add_order_email_instructions( $order, $sent_to_admin ) {
if ( 'paypal' == $order->payment_method && ! $sent_to_admin ) {
echo 'my text:';
}
}
I have tried with additional conditionals, like ! $order->has_status( 'processing' )
, but nothing is working. Any help?
I wanted to only add a note to emails that had a status of “on-hold” and sent to admins (not customers). This worked well for me:
I believe that my patch should be available with WooCommerce 2.5. When it is, then the
$email
object will be available on thewoocommerce_email_before_order_table
hook (and on other hooks in the emails) and you will be able to test the$email->id
for specific emails. Something like the following in yourfunctions.php
(or preferably in a plugin) should do it:Ops… I don’t know why I thought your email was not firing at all.
By the way, if you wanna add that text only to specific email template, there are 2 ways:
harder one: disable ‘customer-order-processing’ and create your own email template. You can start by this tutorial: https://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/
easier one and recommended: override ‘customer-order-processing.php’ and add some code in that template.
This are the steps:
go in WooCommerce -> Settings -> Email -> Processing Order and click ‘Copy files to theme’.
if it doesn’t exist, a ‘woocommerce’ folder will be created in your theme folder and you will find the template file in woocommerce -> emails
open ‘customer-processing-order.php’ and add needed code where you prefer:
Code is not tested but should work!
Good luck 😉