I am looking to add the shipping address from the order to the New Order email. Can anyone please provide detailed information on how to do so? I am pretty new to editing functions.php, hooks, etc.
Thanks
Use this
you can comment out the conditional part if you want to have it on customer email as well.
add_action( 'woocommerce_email_after_order_table', 'woocommerce_add_shipping_address_to_admin_emails', 15, 2 );
function woocommerce_add_shipping_address_to_admin_emails( $order, $is_admin_email ) {
if ( $is_admin_email ) {
echo '<p><strong>Shipping Address:</strong> ' . $order->get_formatted_shipping_address() . '</p>';
}
}
Thank you for this snippet. It works perfectly! Here is a version which separates header (shipping address) from content:
add_action( 'woocommerce_email_after_order_table', 'woocommerce_add_shipping_address_to_admin_emails', 15, 2 );
function woocommerce_add_shipping_address_to_admin_emails( $order, $is_admin_email ) {
if ( $is_admin_email ) {
$header = '<p><strong>Shipping Address:</strong> ' . '</p>';
$shippingInfo = '<p>' . $order->get_formatted_shipping_address() . '</p>';
echo $header;
echo $shippingInfo;
}
}
Related
Hello I have a woo commerce website and I am selling some books every thing is cleared but I need create custom order tracking functionality in woo commerce code to add order tracking functionality for end user is it possible if possible how can I do this please help me.
I create a custom page name as woocommerce-custom-order-tracking.php
and code is given below
<?php
// Register a custom endpoint to handle order tracking
function wc_register_order_tracking_endpoint() {
add_rewrite_endpoint( 'order-tracking', EP_PAGES );
}
add_action( 'init', 'wc_register_order_tracking_endpoint' );
// Display the order tracking form
function wc_display_order_tracking_form() {
if ( ! is_wc_endpoint_url( 'order-tracking' ) ) {
return;
}
// Get the order id from the query string
$order_id = absint( $_GET['order_id'] );
// Get the order
$order = wc_get_order( $order_id );
if ( $order ) {
// Display the order tracking information
echo '<p>Order Number: ' . $order->get_order_number() . '</p>';
echo '<p>Order Status: ' . wc_get_order_status_name( $order->get_status() ) . '</p>';
echo '<p>Tracking Number: ' . get_post_meta( $order_id, '_tracking_number', true ) . '</p>';
} else {
echo '<p>Invalid order ID.</p>';
}
}
add_action( 'woocommerce_before_single_product', 'wc_display_order_tracking_form' );
I have a holiday letting wordpress site which has the advanced custom field "Supplier Email" in the add listing page. When a rental is booked the Supplier Email needs to be added to the woocommerce New Order email under BCC, i have tried numerous options but they have not worked, the Supplier Email is in the post meta so it needs to be pulled in to the new order email. This is the code i have in my functions.php file:
add_filter( 'woocommerce_email_headers', 'bcc_to_email_headers', 10, 3 );
function bcc_to_email_headers( $headers, $email_id, $order ) {
if ( $email_id === 'new_order' ) {
$supplier_email = get_field( 'supplier_email_main',$post_id);
if ( $supplier_email ) {
$headers .= "CC: Supplier <" . $supplier_email . ">\r\n";
$headers .= "BCC: New Order <myemail#gmail.com>" . "\r\n";
}
}
return $headers;
}
The gmail address(this would go to my personal email, have hidden it here for obvious reasons) i added to BCC didnt even get sent. Not sure how to proceed with this, any help would be greatly appreciated, please note i am not a wordpress developer. Thanks in advance.
try this
add_filter( 'woocommerce_email_headers', 'add_bcc_header', 10, 3 );
function add_bcc_header( $headers, $id, $order ) {
if ( $id == 'new_order' ) {
$headers .= 'Bcc: gmailaddress#gmail.com' . "\r\n";
}
return $headers;
}
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;
}
I'm new to Woocommerce, and I'm trying to show the name of the customer in the beginning of the email.
So the email will look something like this:
[HEADER]You order has been placed [/HEADER]
[H2]Hi {CUSTOMER_NAME}[/H2]
[P]Some text[/P]
[THE REST OF THE MAIL]
I've tried adding something like this to functions.php in my theme.
//add the first name of the person to the email.
add_filter('woocommerce_email_order_details','name_to_processing_customer_email', 10, 3);
function name_to_processing_customer_email( $order, $sent_to_admin, $plain_text, $email ) {
if( 'customer_processing_order' == $email->id ){
// Set here as you want your custom content (for customers and email notification related to processing orders only)
echo '<h2>Hej '.$order->billing_first_name .'</h2>';
}
}
But this doesn't work.
Can someone help?
Try this One ::
add_filter('woocommerce_email_order_details','name_to_processing_customer_email', 10, 3);
function name_to_processing_customer_email( $order_id, $sent_to_admin, $plain_text, $email ) {
$order = new WC_Order( $order_id );
echo '<h2>Hej '.$order->billing_first_name .' '.$order->billing_last_name.'</h2>';
}
add_action( 'woocommerce_email_after_order_table', 'name_to_processing_customer_email', 10, 2 );
function name_to_processing_customer_email( $order, $is_admin_email ) {
echo '<p><h4>Shipping:</h4> ' . $order->get_billing_first_name() . '</p>';
}
Check this WC3 snippet