简体   繁体   中英

Change sender name to customer billing full name in WooCommerce email notifications

How can I change E-Mail Sender Name into customer “Billing First & Last Name” using woocommerce_email_from_name hook?

For Example: "My Shop" should be changed to "John Doe".

Based on Change sender name and email address for specific WooCommerce email notifications answer code, here is my function:

    add_filter( ‘woocommerce_email_from_name’, function( $from_name, $wc_email ){
if( $wc_email->id == ‘customer_processing_order’ )
// $from_name = ‘Jack the Ripper’;
$from_name = get_user_meta( $user_id, ‘first_name’, true, $user_id, ‘last_name’, true );
//$from_name = get_user_meta( $user_id, ‘first_name’, true );
return $from_name;
}, 10, 2 );

ut it doesn't work. Can anyone help me?

The following will change the "From name" to customer billing full name on Woocommerce email notifications:

add_filter( 'woocommerce_email_from_name', 'filter_wc_email_from_name', 10, 2 );
function filter_wc_email_from_name( $from_name, $email ){
    if( is_a($email->object, 'WC_Order') ) {
        $order     = $email->object;
        $from_name = $order->get_formatted_billing_full_name();
    }
    return $from_name;
}

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


Addition: For "new order email notification, you will use:

add_filter( 'woocommerce_email_from_name', 'filter_wc_email_from_name', 10, 2 );
function filter_wc_email_from_name( $from_name, $email ){
    if( $email->id == 'new_order' && is_a($email->object, 'WC_Order') ) {
        $order     = $email->object;
        $from_name = $order->get_formatted_billing_full_name();
    }
    return $from_name;
}

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

Related: Change sender name and email address for specific WooCommerce email notifications

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM