Let’s face it. Most default email templates for WooCommerce are hideous. Yes, indeed, you can customize them in the settings. We needed a simple change to add a proper salutation to the email because we’re proper like that.
Thank you for creating an account on …
… and so on
Turns out, it’s super easy to do.
This is tested on WordPress 4.9.7 with WooCommerce 3.4.3. We use Sage 9, but this shouldn’t be any different in any other theme. The email template we’ll work with hasn’t changed since WooCommerce 1.6.4.
I used a sweet email testing plugin called Woo Preview Emails that allows you to see emails without sending a billion of them to yourself.
Copy template to theme
Get the email template for a new account from
plugins/woocommerce/templates/emails/customer-new-account.php and copy it to your theme’s
woocommerce directory. For more on this, don’t ask me, refer to the WooCommerce Template structure & Overriding templates via theme docs.
Get the user’s first name
WC_Email_Customer_New_Account class has the username available to it via
$user_login, we can set up a variable for the user based on the slug of
$user_login using WordPress’s very own get_user_by function, like so:
<?php $email_user = get_user_by( 'slug', $user_login ); ?>;
Add this to around line 26 in
Then, you can add a new line above the stock “Thanks for creating an account on …”, like so: Copy the template to your theme, set up a variable to get the user info, then get the Namaste.
<p><?php printf( __( 'Dear %1$s,' ), esc_html( $email_user->first_name ) ); ?></p>
first_name from it.
Copy the template to your theme, set up a variable to get the user info, then get the