0

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.

0

If you copy the template for that email so that it is overridden by your child theme, then you can modify that email only.

To copy the template easily, go to Woocommerce -> Settings -> Emails -> Processing Order and click the button at the bottom of the screen to copy the template.

0

If you are using oops, then you have to write as

add_action( 'woocommerce_email_before_order_table',array($this,'add_order_email_instructions'), 0, 2 );
0

I've made some changes to your code below:

add_action( 'woocommerce_email_before_order_table', 'add_order_email_instructions', 20, 4 );
function add_order_email_instructions( $order, $sent_to_admin, $plain_text, $email ) {
    if ( $email->id == 'customer_processing_order' && 'paypal' == $order->payment_method && ! $sent_to_admin ) {
        echo 'my text:';
    } 
}

I've checked if the current email is customer_processing_order. I also have made changed in your add_action and function parameter to get $email object in function for checking email if.

Hope that works for you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.