woocommerce add text to specific email

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:

Read More
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?

Related posts

3 comments

  1. 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:

    /* Add manual processing note to new orders to admin */
    add_action( 'woocommerce_email_order_details','add_order_email_instructions', 10, 4 );
    function add_order_email_instructions( $order, $sent_to_admin, $plain_text, $email ) {
        if ( $order->status == 'on-hold' && $sent_to_admin ) {
            echo '<p><strong>Note: Manual processing for this order is required.</strong></p>';
        } 
    }
    
  2. I believe that my patch should be available with WooCommerce 2.5. When it is, then the $email object will be available on the woocommerce_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 your functions.php (or preferably in a plugin) should do it:

    add_action( 'woocommerce_email_before_order_table','add_order_email_instructions', 10, 4 );
    function add_order_email_instructions( $order, $sent_to_admin, $plain_text, $email ) {
        if ( 'customer_processing_order' == $this->id && 'paypal' == $order->payment_method && ! $sent_to_admin ) {
            echo 'my text:';
        } 
    }
    
  3. 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:

    1. 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/

    2. 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:

      if( 'paypal' == $order->payment_method ) {
       echo 'my text:';
      }
      

    Code is not tested but should work!

    Good luck 😉

Comments are closed.