Today we take a look at the WooCommerce Emails and specifically at how to change the subject of the Customer Processing Order email by adding the billing “First Name”. As usual, this is a matter of 3 lines of PHP code – feel free to copy/paste and customize it to your liking 🙂
PHP Snippet: Add Billing First Name to Order Email Subject
/**
* @snippet Add Billing First_name to Email Receipt (Customer Processing)
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 3.8
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_email_subject_customer_processing_order', 'bbloomer_change_processing_email_subject', 10, 2 );
function bbloomer_change_processing_email_subject( $subject, $order ) {
$subject = $order->get_billing_first_name() . ', thanks for your order!';
return $subject;
}
Hello. Sorry, English is not my native language.
I only have one product per order. It is possible to add the product name in the subject field of the email to the admin?
Hello Arthur, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
You code works, but in my case the name is left out. i.e. the billing_first_name is blank.
Its like it is not fetching the billing_first_name from the database. – do you have any suggestions?
Hi Clifford, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet.
To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentytwenty” theme (load the snippet there in functions.php) as explained here: https://www.businessbloomer.com/lesson/trwm4l01/
Once you do that, does it work? If yes, you have a problem with your current theme or one of the plugins.
Hope this helps!
Is there a way to add Billing First Name to Order email customer details section only?
Hi Diksha, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi,
how can I change E-Mail Sender Name (woocommerce_email_from_name) into “Billing First & Last Name” from User.
For Example: My Shop should be changed to John Doe!
Can anyone help me?
Thanks.
Hi Nero, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi please I want to remove costumer e-mail and phone number from new e-mail how do I do that?
Hello there, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Hi, this is causing an error in my PHP log
billing_first_name was called incorrectly. Order properties should not be accessed directly.
Backtrace: require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), do_action(‘template_redirect’), WP_Hook->do_action, WP_Hook->apply_filters, WC_AJAX::do_wc_ajax, do_action(‘wc_ajax_checkout’), WP_Hook->do_action, WP_Hook->apply_filters, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, WC_Stripe_Subs_Compat->process_payment, WC_Gateway_Stripe->process_payment, WC_Stripe_Payment_Gateway->process_response, WC_Order->payment_complete, WC_Order->save, WC_Order->status_transition, do_action(‘woocommerce_order_status_pending_to_processing’), WP_Hook->do_action, WP_Hook->apply_filters, WC_Emails::send_transactional_email, do_action_ref_array, WP_Hook->do_action, WP_Hook->apply_filters, WC_Email_Customer_Processing_Order->trigger, WC_Email->get_subject, apply_filters(‘woocommerce_email_subject_customer_processing_order’), WP_Hook->apply_filters, bbloomer_change_processing_email_subject, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.
100% right Ruth! Snippet has now been revised 🙂
Hi,
I wrote in subject:
$subject = $order->billing_first_name . ‘, il tuo ordine è stato spedito!’;
but in email ‘è’ appear ‘?’ char,
how can I fix it?
Ciao Domenico, thanks for your comment. I’m not 100% sure why, it should encode that special character by default. Try taking a loook at https://stackoverflow.com/questions/29069667/all-special-characters-are-question-marks-in-php-html
Hi.
The code is working fine, but i want something different and i can’t make it work. I need to have a email headind that looks like this : Hi, {customer_name}. It looks simple but i did not find the solution. Is there a solution? Thank you.
Ciao Beppe, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Hi!
Is there an option to use always first name as salutation in the mail subject, no matter whats in the email?
Thanks!
Hey Hansimglück thanks for your comment! You can add more email types by using extra filters. I’m using “woocommerce_email_subject_customer_processing_order” but you can also use “woocommerce_email_subject_XYZ”, where “XYZ” is the ID of the email you like 🙂
Hello Rodolfo,
Your tips are amazing! It really helped me to figure out how to customise the emails. At one point i can’t find any help or information on the web: How do actually change the standart text in the Emails (for example the one from the processing-email: Your order has been received and is now being processed. Your order details are shown below for your reference:). I really would like to add the customer name there without a big mess and overriding templates. Do you know an easy way?
Hey Simon, thanks for your comment! The only way to edit that without overriding the email template is probably to echo your new message with the hook “woocommerce_email_order_details” (use priority < 10 so it shows before the order table), and then hide the default WooCommerce message with CSS I guess. Hope this helps!
Is there a way to strip out the download link in customer-completed-order email?
Hal, thanks for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
hii i want to add account number of buyer and seller in order details and emails
Hey Bhavik, sorry but this is custom work and I can’t help this time 🙂
Is there a way/snippet that let’s you put the category of a product to the email?
I just can’t find any good information on how to get to that data. (I think it is woocommerce_order_item_meta data?)
Hello Hans, thanks for your comment! Try watching my video tutorial here: https://businessbloomer.com/customize-emails-woocommerce, it should help you hopefully! 🙂
Just a question – Will this work 🙁 ? I need to add invoice No
add_filter(‘woocommerce_email_subject_customer_completed_order’, ‘bbloomer_change_processing_email_subject’, 10, 2);
function bbloomer_change_processing_email_subject( $subject, $order ) {
global $woocommerce;
$subject = $order->billing_first_name . ‘, Thanks for your ‘ . get_bloginfo( ‘name’, ‘display’ ) . ‘ Order!’ .. ‘Invoice No’;
return $subject;
}
Sorry Prachi, this is custom to the Invoice plugin you’re using. You need to check how to get the Order Number from there 🙂
Great 🙂
Can I add something similar to First_name to Email when an order has been completed ? Which is the respective hook ?
Prachi, thanks for your comment! Of course – just change woocommerce_email_subject_customer_processing_order with woocommerce_email_subject_customer_completed_order. Docs here: https://docs.woothemes.com/document/change-email-subject-lines/
Where do you add this snippet?
Hey, thanks for your comment! You should add this snippet in the functions.php file of your child theme. This free video training I recorded may help you 🙂 Thank you!