How to add "Reply To" with Woocommerce Client Name and Email

Asked

Viewed 158 times

1

Hello,

I have a big problem in this part, I would like to set the name of the Customer instead of only the E-mail when clicking Reply. Below the code I used to work "Reply To":

add_filter( 'woocommerce_email_headers', 'add_reply_to_wc_admin_new_order', 10, 3 );

function add_reply_to_wc_admin_new_order( $headers = '', $id = '', $order ) {
    if ( $id == 'new_order' ) {
        $headers .= "Reply-To: ".$order->billing_email."\r\n"; 
    }
   return $headers;
}

As you can see this code works as follows, when replying to the Woocommerce’s new order email it will respond to the Customer’s Email filled in the Store’s Billing Form. I would also like to put the name of the Client.

An example I’m trying to explain is from Phpmailer that works this way:

$mailer->AddReplyTo($_POST["email"], $_POST["nome"]);

In this model of Phpmailer when clicking reply it does more or less that:

Rodrigo Macedo <[email protected]>, 

Does anyone have an idea how I can do that ?

I have tried to add the code in several ways in the name in front of the E-mail similar to Phpmailer but without success...

  • The question seems ok to me, how do you get the customer’s name? is the $_POST["nome"] even?

  • @rray So this was an example that I gave, and as for your question, that’s right, this code is used to get the name of the customer that he fills in the form, this code is by Phpmailer that I use to send authenticated forms on my Websites, in case I want to do the same thing in the Woocommerce form however as I don’t have much knowledge in programming I’m not getting..

1 answer

1

  • Brother, your code would be perfect if you were just to put the Customer Email and Name in front as you said, but there is one though, I am doing this in the Woocommerce Address and to get the Customer Email I have to use the following code: $headers .= " Reply-To: ". $order->billing_email." r n"; The problem is I put the client name, I tried the following: $headers .= " Reply-To: ". $order->billing_name."". $order->billing_email." r n"; However, sending is not done...

  • @Roohmacedo According to his code, the chevrons (<>) email. This is the default form, there’s no way it won’t work.

  • So I tried to add the chevrons in several ways (<>), added the following ways: 1ª $headers .= " Reply-To: ". $order->billing_name."" <. $order->billing_email. >" r n"; 2ª $headers .= " Reply-To: ". $order->billing_name. <. $order->billing_email. >" r n"; //No quotes between the two. and for last 3ª $headers .= " Reply-To: ". $order->billing_name." <". $order->billing_email." >"r n"; but none of the ways I tried to work, there’s something wrong ?

  • With the exception of missing a space between the name and the chevron. In theory, the correct would be (the code varies, consider only the result): "Reply-To: {$name} <{$e-mail}>" to have the result as "Reply-To: Nome Cliente <[email protected]>". What is the result you are getting? Any errors, go without the name? Create the string and a var_dump($headers); to see how it was formatted.

  • Still learning about this subject, how do I create this string and give this var_dump ? I tried as follows: $headers .= " Reply-To: ". $order->billing_first_name." <". $order->billing_email." > r n"; but that way he didn’t get the name of the Client, it was only the E-mail, then when I click to reply in the E-mail he only takes the E-mail of the Client.

  • I just did as you reported above: $headers .= " Reply-To: {$order->billing_first_name} <{$order->billing_email}> r n"; But only the Client’s E-mail came, nothing of the Name..

  • It is important to study about string concatenation. Since you’re wearing double quotes, I’d do it like this $headers .= "Reply-To: {$order->billing_first_name} <{$order->billing_email}>\r\‌n";. The var_dump would be in the $headers variable, before the Return $headers, to check how the string is being formatted.

  • I just commented rsrs, I did this way that you formatted the code, however came only the E-mail, the name did not come, will it is better I create this var_dump what you said ?

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.