Add Payment Type to WooCommerce Admin Email

Here’s a little snippet to add the order payment type to the WooCommerce Admin New Order email, in an upgrade-safe manner:
add_action( 'woocommerce_email_after_order_table', 'add_payment_method_to_admin_new_order', 15, 2 );
function add_payment_method_to_admin_new_order( $order, $is_admin_email ) {
if ( $is_admin_email ) {
echo 'Payment Method: ' . $order->payment_method_title . '
';
}
}
Add that bit of code to your theme’s functions.php file, or even to your own custom site plugin. All manner of order details can be added to the admin email in the same way, for quick reference. See the WC_Order class for the full set of order attributes available.
Is it also possible to add extra payment instructions in the order mail to the customer? When a customer chooses cash on delivery as a payment option, I would like to add that payment choise and some the extra info about paying in the order mail.
Certainly, just check for the payment method (ie $order->payment_method == ‘cod’) and then display any instructions you might want.
Hi!
I followed your instructions to get the order method to be displayd in admin new order email, but I still don’t get it how to get it to be displayd also in customer new order email. I don’t know anything about php actually. Can you post the entire code I have to put into the functions.php file?
Hi,
I wonder if you could help me…
I have the Delivery Date plugin for Woocommerce that I got from here:
http://wordpress.org/extend/plugins/order-delivery-date-for-woocommerce/
I have tried so many times to use the above code to display the date that the customer has picked, but I just can’t get it to work. As far as I can tell the above plugin creates a custom field called e_deliverydate that appears in the Woocommerce admin backend when you look at each customer’s order.
When I try to get this field to appear in the email by replacing:
echo ‘Payment Method: ‘ . $order->payment_method_title . ‘
with
echo ‘Requested Delivery Date: ‘ . $order->e_deliverydate . ‘
I just get the “Requested Delivery Date:” text and no actual date displayed.
Any help is greatly appreciated.
Jamie
(Edit, meant to say:) Hey Jamie, try this instead:
$order->order_custom_fields['e_deliverydate'][0]Wow, thanks for the speedy response! I tried that and still the same thing is happening. Maybe this will help, here is the part of the code for the delivery date plugin I’ve been looking at:
add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');function my_custom_checkout_field_update_order_meta( $order_id ) {
if ($_POST['e_deliverydate']) {
update_post_meta( $order_id, 'Delivery Date', esc_attr($_POST['e_deliverydate']));
Not sure if that helps or not. I can copy the whole code if the above isn’t any use.
Many thanks again,
Jamie
Ha ha, yeah you got lucky that I just happened to check for comments right after you posted. Anyways, thanks for posting the additional code and clarification, the field name is actually ‘Delivery Date’, so you’d want to use:
$order->order_custom_fields['Delivery Date'][0]Brilliant! Thank you so much for that, it worked perfectly.
I am still learning code, sometimes it seems to make sense to me, but clearly this time I would never have figured out the right field to use.
Many thanks again.
Jamie
You’re welcome Jamie, glad I could help. It’s not easy when you’re getting started, but there are a lot of resources out there. The wordpress codex is extremely helpful, for instance: update_post_meta() tells you that the second parameter to the
update_post_meta()function is the meta key, or name of the field that you need to retrieve.There’s no obvious reason why the WooCommerce order object would store the value in that
order_custom_fieldsmember, so to figure that out you just have to take a look at the WooCommerceclass-wc-order.phpfile and figure out where the post meta is getting set. Only special post meta are available like$order->payment_method_title, but they are all available from thatorder_custom_fieldsmember like I showed you. Keep at it, you’ll get there.Also, remember remember the fifth of november… lol
Thanks for the extra info, I will have a read of that in more depth.
Having worked on the website for the past few weeks, I don’t want to see another firework for a very long time!
Hi Justin,
I’m back! Just another quick question – In the email sent to admin it successfully shows the delivery date if a customer adds one (thanks for your help with this), but having placed about another 100 test orders with all possibilites covered; if a customer does not specify a date then the text “Required Delivery Date” still appears.
Is there any way to hide this text if no date is specified by the customer?
Many thanks in advance,
Jamie
Sure, you would just do:
if ( isset( $order->order_custom_fields['Delivery Date'][0] ) && $order->order_custom_fields['Delivery Date'][0] ) {
echo "Requested Delivery Date: " . $order->order_custom_fields['Delivery Date'][0];
}
Brilliant, thanks for that. I’m really not very good at this, I’ve just changed what I had from:
{if ( $is_admin_email ) {
echo 'Requested Delivery Date: ' . $order->order_custom_fields['Delivery Date'][0] . '';
}
}
to
{if ( $is_admin_email ) {
echo 'Requested Delivery Date: ' . if ( isset( $order->order_custom_fields['Delivery Date'][0] ) && $order->order_custom_fields
['Delivery Date'][0] ) {
echo "Requested Delivery Date: " . $order->order_custom_fields['Delivery Date'][0];
} . '';
}
}
and managed to break my site. What have I done wrong?
Sorry for my inexperience of working this out!
Jamie
Is there away to add a payment link to a New Customer Email Order? I would like to create a manual order, then email the invoice out to the customer where they can click on a link to view the order and then pay for it if they like.
Hey matt, any reason why you can’t use the “Email invoice” button found in the Order Actions panel within the Order admin? That should include a payment link in the email it dispatches.
I have tried to change the status of the order and “email invoice”, however the email comes back as a simple email. There aren’t any links in the email, even the footer has my website address but it doesn’t “click through”.
Where is the link generally located on the email?
Is there a setting that I am missing within WooCommerce?
Well, not entirely sure what you mean by the email being “simple”, but make sure you have the status as “pending” when you send the invoice, as “pending” indicates an unpaid order. See the managing ordes article from WooThemes for additional details on how to properly manage the order status’
Hi Justin,
I just Read all Problems and your Brilliant solutions Here!
I am having an very serious issue with woocommerce, Hope you help me better….
I want to Integrate woocommerce with Specter Business Management system, I Have an API Doc and an PDF file from specter. (if you need i can send you)
Although i am not able to integrate the order system to specter CRM, Should i edit the “class-wc-order.php” file to Integrate their API?
TOTAL CONFUSED!!! PLEASE HELP ME TO SOLVE THIS!!
Regards
deepak
Hey Deepak, thanks for the question. Integrating with a CRM system is a fairly monumental undertaking. Unless you’re a software engineer, and ideally one skilled with PHP and WordPress/WooCommerce, I’d highly recommend finding and contracting with a developer you trust to implement this for you.
Justin,
First off, thank you for all of this information and all of the work you’ve put into this site. It’s incredibly helpful for those of us novices who are trying to make our sites function properly.
I was wondering if there was a simple way to add a cc: or bcc: to the emails that are sent to the customer from woocommerce. Specifically, I would like to receive a copy of the email that gets sent to a customer when I click the “email invoice” button on the edit order screen.
If there were a plugin for this I would be more than happy to purchase it. If it involves anything more than a simple line or two of code please let me know and I’ll happily work out some payment for your time.
Thanks in advance!
Hello,
Thanks for the line of code it works perfectly! :]
Would anyone know how to add a products unit price to the admin emails? Currently there’s only the total order amount.
Thanks!
Hey Angel, I guess you’d need to override a template file:
woocommerce/templates/emails/email-order-items.phpand include a call to$_product->get_price_html()wherever you needed. Keeping in mind though that this will be displayed on all emails, both to the admin and customers.That worked very well! thanks for that!
I had to change the admin and customer pages as well. Because when that got added it made Quantity go under the price.
To fix that I added
“Unit Price”
to admin-new-order.php, customer-processing-order.php, customer-note.php, and customer-invoice.php
I also changed this line to a colspan of 3
“<th scope="row" colspan="3" style="text-align:left; border: 1px solid #eee; “>”
Thanks again!
whoa my code from the previous comment go omitted.
Hi Just wondering if you can help- i added your code above in my /public_html/wp-content/plugins/woocommerce/templates/emails/admin-new-order.php file. however it just comes up with ..add_action( ‘woocommerce_email_after_order_table’, ‘add_payment_method_to_admin_new_order’, 15, 2 ); function add_payment_method_to_admin_new_order( $order, $is_admin_email ) { if ( $is_admin_email ) { echo ‘Payment Method: ‘ . $order->payment_method_title . ”; } }
under the tel number in the email to the admin. What have i done wrong in my code?
Hey Jacinta, actually you just want to put that code into your theme’s functions.php file, it’s not necessary to actually put that into the email template file