Viewing 5 replies - 1 through 5 (of 5 total)
  • I was looking for the same, can’t find anything about it. I hope someone can give us the proper code for it..

    Add this snippet to functions.php
    First name, last name and mail of customer gets added to new order email. I have no knowledge of coding, soa no idea how to adjust this code to get other results like putting in username.

    /**
    * add customer name and email to new order mail
    */
    function custom_use_customer_from_address ( $from_email, $obj ) {
    	if ( is_a( $obj, 'WC_Email_New_Order' ) ) {
    		$address_details = $obj->object->get_address( 'billing' );
    		if ( isset( $address_details['email'] ) && '' != $address_details['email'] ) {
    			$from_email = $address_details['email'];
    		}
    	}
    	return $from_email;
    }
    add_filter( 'woocommerce_email_from_address', 'custom_use_customer_from_address', null, 2 );
    
    function custom_use_customer_from_name ( $from_name, $obj ) {
    	if ( is_a( $obj, 'WC_Email_New_Order' ) ) {
    		$address_details = $obj->object->get_address( 'billing' );
    		if ( isset( $address_details['first_name'] ) && '' != $address_details['first_name'] ) {
    			$from_name = $address_details['first_name'];
    		}
    		if ( isset( $address_details['last_name'] ) && '' != $address_details['last_name'] ) {
    			$from_name .= ' ' . $address_details['last_name'];
    		}
    	}
    	return $from_name;
    }
    add_filter( 'woocommerce_email_from_name', 'custom_use_customer_from_name', null, 2 );

    Hi,

    Am also looking to find a way of displaying/printing the USERNAME of the customer placing the order in the New Order email.
    All help appreciated! ??

    Correction, I’m actually needing to show the customers NICKNAME in my email.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to add customers username on New Order Email notification for Admin’ is closed to new replies.