Reputation: 41
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?
Upvotes: 0
Views: 148
Reputation: 3126
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;
}
Upvotes: 4