1
votes

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?

1

1 Answers

1
votes

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