some time ago when the customers made a new order, in the mail header the "reply-to" was not shown in the mail that came to me (as an admin), but now if, and I need to avoid showing it, I have tested with
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' ) {
$reply_to_email = $order->billing_email;
$headers .= "Reply-to: <custom#custom.com>\r\n";
}
return $headers;
}
but the client's email keeps appearing in the reply-to, any idea? How to solve this?
here is your solution to keep only the header type without Reply to:
add_filter('woocommerce_email_headers', 'add_reply_to_wc_admin_new_order', 10, 3);
function add_reply_to_wc_admin_new_order($header = '', $id = '', $order)
{
$wc_email = new WC_Email(); //instantiate wc meail
if ($id == 'new_order') {
$reply_to_email = $order->billing_email;
$header = 'Content-Type: ' . $wc_email->get_content_type() . "\r\n";
}
return $header;
}
Related
I have gift cards plugin that is sending a custom email template to the user. How do I manipulate that email header in my functions.php file and add a BCC based on a custom order meta? That order meta has an email address in the value.
add_filter( 'woocommerce_email_headers', 'order_completed_email_add_bcc', 9999, 15 );
function order_completed_email_add_bcc( $headers, $email, $order ) {
if ( 'pw_gift_card' == $email ) {
$bcc = get_post_meta( $order->id, 'my_custom_order_meta', true );
$headers .= "Bcc: ".$bcc."" . "\r\n";
}
return $headers;
}
Your code seem to be alright although it needs improvement. You have 3 arguments and not 15. Also for brevity, use $order->get_meta() instead of get_post_meta().
add_filter( 'woocommerce_email_headers', 'order_completed_email_add_bcc', 9999, 3 );
function order_completed_email_add_bcc( $headers, $email_id, $order ) {
if ( 'pw_gift_card' == $email_id && $bcc = $order->get_meta('my_custom_order_meta')) {
$headers .= 'Bcc: ' . $bcc . '\r\n';
}
return $headers;
}
I created a custom field in Woocommerce for a second customer email address:
purchase_order_email
Now I need Woocommerce to use that email adres to send invoices to as wel as the standard customer email address.
Hope you can help.
I'm using Woocommerce PDF invoices & Packing Slips plugin for invoices.
Just found this code which should work but gave a fatal error: A non expected 'if'.
add_filter( 'woocommerce_email_headers', 'wcpdf_email_cc_alternative',
10, 3);
function wcpdf_email_cc_alternative( $headers, $email_id, $order ) {
if ($email_id == 'customer_completed_order') {
$alternative_email = get_post_meta( $order->id,
'purchase_order_email', true)
if ( $alternative_email ) {
$headers .= 'CC: ' . $alternative_email . "\r\n"; //just repeat
this line again to insert another email address in BCC
}
}
return $headers;
}
Thanks in advance!
EDIT
Found a solution
Code needed to be adjusted to (was missing a semicolon and get_post_meta needed to be changed to get_meta):
add_filter( 'woocommerce_email_headers', 'wcpdf_email_cc_alternative',
10, 3);
function wcpdf_email_cc_alternative( $headers, $email_id, $order ) {
if ($email_id == 'customer_completed_order') {
$alternative_email = $order->get_meta( 'purchase_order_email', true
);
if ( $alternative_email ) {
$headers .= 'CC: ' . $alternative_email . "\r\n"; //just repeat
this line again to insert another email address in BCC
}
}
return $headers;
}
When someone makes an order in woocommerce, he gets also an email when the order is complete. I'd like to add additional recipients for this email. However! I'd only like this extra BCC to be made on these exact mails. Not all the other mails going through.
It's something like this, but then with the correct filter / name: add_bcc_to_wc....
add_filter( 'woocommerce_email_headers', 'add_bcc_to_wc_admin_new_order', 10, 3 );
function add_bcc_to_wc_admin_new_order( $headers = '', $id = '', $wc_email = array() ) {
if ( $id == 'new_order' ) {
$headers .= "Bcc: my_personal#email.com\r\n"; // replace my_personal#email.com with your email
}
return $headers;
}
With kind regards,
Dennis
Add bcc e-mail to customer order confirmation
add_filter( 'woocommerce_email_headers', 'firefog_headers_filter_function', 10, 2);
function firefog_headers_filter_function( $headers, $object ) {
if ($object == 'new_order') {
$headers .= 'BCC: NAME <name#domain.com>' . "\r\n";
}
return $headers;
}
Is there way to add additional recipients to woocommerce invoice mail.
I have tried to use 'woocommerce_email_headers' hook, but it's not working:
add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 2);
function mycustom_headers_filter_function($headers, $object) {
$headers = array();
$headers[] = 'Bcc: My Name <me#gmail.com>';
$headers[] = 'Content-Type: text/html';
return $headers;
}
Any advice?
You can expand the function to include the order as well:
add_filter( 'woocommerce_email_headers', 'woo_cc_emails', 10, 3 );
function woo_cc_emails( $headers, $status, $object ) {
return 'Bcc: your#email.here' . "\r\n";
}
Some months later, but I hope this will help someone.
add_filter('woocommerce_email_headers', 'woo_cc_emails');
function woo_cc_emails() {
return 'Bcc: your#email.here' . "\r\n";
}
You can change "Bcc", with "To" or "Cc".
I needed help to add a BCC to a New Customer Account email. Here is what I came up with. It's slightly different than above. Hope this helps someone.
add_filter( 'woocommerce_email_headers', 'add_bcc_to_wc_customer_new_account', 10, 3 );
function add_bcc_to_wc_customer_new_account( $headers = '', $id = '', $wc_email = array() ) {
if ( $id == 'customer_new_account' ) {
$headers .= "Bcc: my_personal#email.com\r\n"; // replace my_personal#email.com with your email
}
return $headers;
}
This script was working perfectly for costum twitter URL shortener but for some reason it just started to put broken links.
And now all links are broken even those from before which were good.
It is showing on twitter domain.com/p(somenumber) and it is opening in browser that URL instead to redirecting to post. I guess the problem is in this Perl code which is autoposting wordpress posts on twitter.
#!/usr/bin/perl -s
use strict;
use Data::Dumper;
use XML::Simple;
use Net::Twitter;
use Scalar::Util 'blessed';
use WWW::Facebook::API;
use JSON::Any;
use lib '/var/www/perl/.';
use MyLib::DB;
use MyLib::Settings;
my $settings = new Settings();
my $config = $settings->getConfig();
my $db = new DB(
dsn =>$config->{sql_connection}->{dsn},
database =>$config->{sql_connection}->{database},
server =>$config->{sql_connection}->{server},
login =>$config->{sql_connection}->{login},
password =>$config->{sql_connection}->{password}
);
my %posts = $db->getList('select * from add_ready_post where wp_id > ( select max(wp_id) from add_ready_post where is_sent=1 ) and post_title <> "" limit 1;');
my $nt = Net::Twitter->new(legacy => 0);
my $nt = Net::Twitter->new(
traits => [qw/OAuth API::REST/],
consumer_key => '',
consumer_secret => '',
access_token => '',
access_token_secret => '',
);
map {
my $message = $posts{$_}[4];
my $id = $posts{$_}[0];
my $url = ' domain.com/p' . $posts{$_}[1];
if ( $message ne '' )
{
# print 'Original: ' . $message . "\n";
if ( length( $message ) < 110 )
{
$message = $message . ".";
}
if ( length( $message ) > 110 )
{
$message = substr( $message, 0, 110 );
$message =~ /.*(\s\w+)$/i;
my $newMessage = substr( $message, 0, index( $message, $1 ) );
$message = $newMessage . '...';
}
# print 'Result : ' . $message . $url . "\n";
my $result = $nt->update( $message . $url );
# print Dumper( $result );
# print "\n";
my $sql = "UPDATE add_ready_post SET is_sent=1 WHERE id=" . int( $id ) . ";";
$db->execute( $sql );
}
} keys %posts;
You will probably get closed with "not a real question" - but anyway - few comments:
Haven't idea what "doing" your MyLib::DB;, so can't analyze the code without knowing what contains the %posts hash.
Use use warnings; - for example you will get $nt redefined message...
my $nt = Net::Twitter->new(legacy => 0);
my $nt = Net::Twitter->new(
Using map { in this way is not a best practice. It will be much readable using
foreach my $post (keys %posts) {
}
What you'll get when the message will not match here? And what if the index returns -1?
$message =~ /.*(\s\w+)$/i;
my $newMessage = substr( $message, 0, index( $message, $1 ) );
And when the message will contains only spaces? Think about:
if ( $message ne '' )
And here is much more... I'm understand than you learning perl but try decompose the problem to manageable parts and ask an real question.