Add text specifically to order-proceessing-email in WooCommerce

admin2025-01-07  4

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.

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.

Share Improve this question edited Oct 31, 2015 at 17:45 Gabriel 2,24810 gold badges22 silver badges24 bronze badges asked Oct 31, 2015 at 17:29 NilliNilli 113 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 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.

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 );

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!

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736263388a886.html

最新回复(0)