Posted on

WooCommerce: Add First Name to Email Receipts

Today we take a look at the WooCommerce Emails and specifically at how to change the subject of the Customer Processing Order receipt by adding the billing “First Name”. As usual, this is a matter of 3 lines of code – feel free to copy/paste and customize it to your liking 🙂

WooCommerce: change subject of the customer processing order email
WooCommerce: change subject of the customer processing order email

Add Billing First Name to Email Receipt


/**
 * @snippet       Add Billing First_name to Email Receipt (Customer Processing)
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=19870
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.4.3
 */

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 ' . get_bloginfo( 'name', 'display' ) . ' Order!';
return $subject;
}

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

24 thoughts on “WooCommerce: Add First Name to Email Receipts

  1. Hi please I want to remove costumer e-mail and phone number from new e-mail how do I do that?

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

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

    1. 100% right Ruth! Snippet has now been revised 🙂

  3. 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?

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

  4. 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.

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

  5. Hi!

    Is there an option to use always first name as salutation in the mail subject, no matter whats in the email?

    Thanks!

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

  6. 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?

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

  7. Is there a way to strip out the download link in customer-completed-order email?

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

  8. hii i want to add account number of buyer and seller in order details and emails

    1. Hey Bhavik, sorry but this is custom work and I can’t help this time 🙂

  9. 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?)

    1. Hello Hans, thanks for your comment! Try watching my video tutorial here: http://businessbloomer.com/customize-emails-woocommerce, it should help you hopefully! 🙂

  10. 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;
    }

    1. Sorry Prachi, this is custom to the Invoice plugin you’re using. You need to check how to get the Order Number from there 🙂

  11. Great 🙂
    Can I add something similar to First_name to Email when an order has been completed ? Which is the respective hook ?

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

  12. Where do you add this snippet?

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

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.