3

I am very new to WordPress, and have created an e-commerce store with WooCommerce.

After the customer places an order, I get an email and the customer get an email- one for me to say what they have ordered, and one to them as a thank you email.

Within this thank you email, in my functions.php file, I have learned to change the subject of the header to include their name such as this:

//add the first name of the person to the person getting the reciept in the subject of the email. 
add_filter('woocommerce_email_subject_customer_processing_order','UEBC_change_processing_email_subject', 10, 2);

function UEBC_change_processing_email_subject( $subject, $order ) {
global $woocommerce;
$subject = 'Thanks for your ' . get_bloginfo( 'name', 'display' ) . ' Order, '.$order->billing_first_name .'!';
return $subject;
}

The code snippet above works correctly, and is only displayed to the customer, not to me. e.g. "thanks for your order ABCD Clothes order John!". Within the body of the email, I am trying to make this personal as a small thank you message, however, when I make the message, I am using the hook:

add_action( 'woocommerce_email_before_order_table', 'custom_add_content', 20,1 );

I know that since im using the woocommerce_email_before_order_table hook, the custom function will be send in the body of the email to both the customer and myself.

I was wondering, is there a hook that Woocommerce provides so that the custom function will only be sent to the customer within the body of the email?

For example: woocommerce_email_header_customer_processing_order or words to that effect?

Thanks

1 Answer 1

8

To add some custom content using woocommerce_email_before_order_table hook and targeting just the customer "processing order" email notification, you should try this:

add_action( 'woocommerce_email_before_order_table', 'custom_content_to_processing_customer_email', 10, 4 );
function custom_content_to_processing_customer_email( $order, $sent_to_admin, $plain_text, $email ) {

    if( 'customer_processing_order' == $email->id ){

        // Set here as you want your custom content (for customers and email notification related to processing orders only)
        echo '<p class="some-class">Here goes your custom content… </p>';

    }

}

Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.

This code is tested and works

2
  • brilliant, thank you it worked . Out of curiosity, what is the purpose of including all 4 of these arguments in the function when only $email is used? Jan 6, 2017 at 0:40
  • 2
    As $email is the 4th and last argument, you can't remove other ones, and you might need in the future to add some more conditions or some code based on the other arguments (especially on first one)... The most important thing is that this is working for you, or not? Jan 6, 2017 at 8:14

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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