0

How can I add an order number (order_id) to E-Mail Sender Name as follows: #order_id John Doe

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

I am using Change sender name to customer billing full name in WooCommerce email notifications answer code.

Can anyone help me?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Nero
  • 41
  • 3

1 Answers1

4

Use the get_id() function to retrieve the order number and use sprintf() to give your string the desired format, like this:

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 = sprintf( '#%s %s', $order->get_id(), $order->get_formatted_billing_full_name() );
    }
    return $from_name;
}
Terminator-Barbapapa
  • 3,063
  • 2
  • 5
  • 16