How to Change Default From Address in WooCommerce on WordPress

Home » Snippets » How to Change Default From Address in WooCommerce on WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Emails are a crucial aspect of communication for any website or business, providing a direct channel to reach out to your customers and audience. WordPress provides us with the ability to send out emails directly from the platform, but by default, the emails are sent out from your web hosting account’s default email address. In this article, we will illustrate how to change the default from address in WordPress so that your emails will come from a custom email address that you specify.

					function wpturbo_change_email_sender( $original_email_address ) {
    return 'yournewemail@yourdomain.com'; // replace with your own email address
}
add_filter( 'wp_mail_from', 'wpturbo_change_email_sender' );
				

The code snippet you see above is an example of how you can change the default from address in WordPress emails, which is often set to wordpress@yoursitename.com by default.

The code uses the wp_mail_from filter to modify the email sender’s address. The filter accepts the original from address as its parameter, which is passed into our wpturbo_change_email_sender() function as $original_email_address. The function then simply returns a new email address of your choice that you want to set as the new from address.

To customize this code for your own project, replace 'yournewemail@yourdomain.com' in line 2 with the email address you want to use as the new from address. This is useful, for example, if you want to use a custom email address associated with your website, or a branded email address that does not reveal the default CMS being used.

You can add this code to your theme’s functions.php file or your custom plugin file to apply the change sitewide. By hooking into the wp_mail_from filter, the code modifies the email sender’s address for all of the emails sent by WordPress. With this code, you can ensure that your WordPress emails will always come from an address that you control and not from the default WordPress sender email address.

Register an account to save your snippets or go Pro to get more features.