WooCommerce reviews + tutorials

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 '<p><strong>Payment Method:</strong> ' . $order->payment_method_title . '</p>';
  }
}

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.

Published by Justin Stern

Justin is one of our co-founders, and is our resident overengineer. He likes to write developer tutorials and make black magic happen in our plugins. He thinks that writing code is a lot easier than writing words.

70 Comments

  1. 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 there

          Same problem, how do I add the payment type to the Customer e-mail?

          I guess I have to edit customer-processing-order.php

          • Try removing the if ( $is_admin_email ) { check, and the corresponding }. That if statement was limiting the output to the admin emails only, removing it should add the content to all emails

      • Hi… thanks for the code! It worked like a charm with adding it to the functions.php. But as user “marjolein” above me already asked, I also want to add the “payment method” information in order emails which the customers receive. But I don’t really know which file I have to edit and what line of code I exactly have to add??

        I appreciate any help!

        Regards, Michael

        • What “payment method information” do you want to add? If it’s something like last four digits of the card and card type, this will be highly dependent on which payment gateway you use, and might not even be possible without altering the payment gateway.

          • The customer can choose between “paypal” or “cash in advance”… as said, it works perfectly for the admin email which I already tried, but I am trying to modify your code to be able to show the information “Payment Method: PayPal” or “Payment Method: Cash in Advance” in the confirmation emails the customer receives.

      • I kindly ask,
        Where do I put the code in the link below to add payment instructions to emails, please?
        https://gist.github.com/justinstern/9145189

  2. 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_fields member, so to figure that out you just have to take a look at the WooCommerce class-wc-order.php file 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 that order_custom_fields member like I showed you. Keep at it, you’ll get there.

          • Also, remember remember the fifth of november… lol

    • Thanks for your reply.

      Where in functions.php please?
      I added payment type to emails OK, but struggling to add payment instructions.
      I put the code for instructions under the code for payment type in functions.php, but no joy.

      Please forgive my inexperience.
      Do I need to change/remove a small part of either code, please?

      Thank you very much

  3. 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!

  4. 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];

      }

  5. 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

  6. 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 WooCommerce for additional details on how to properly manage the order status’

  7. 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.

  8. 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!

  9. 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.php and 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!

  10. 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

  11. Hi Justin, could you help me please? I know WooCommerce doesn’t send a New Account Email Notification to the Admin. Is it possible do something similar to notify the admin when a new user has registered? Thanks a lot!

  12. Hi, I copy & pasted the code you provided first but I got this error when trying access any page in the site: “Error HTTP 500 (Internal Server Error):”.

    I have the latest version of Woocommerce (2.0.12) Do you know what could we do?

    Thanks!

    • Hey Cesar, sorry to hear this, there must be something misconfigured with your server, I don’t *think* the sample code could cause this

  13. Works like a charm. I don’t know any php, and this was really helpful! Thanks a lot!

  14. Hello Justin,

    I looked into your comments and i hope you can help for my issue,

    I am using custom checkout fields Manager, and restricting custom fields on checkout for Return address,

    My issue is Fields are appearing in all templates which i need to filter ,

    Please help

    Thanks

    • Well if you need to alter the billing or shipping address, there are a lot of filters available in the woocommerce/classes/class-wc-countries.php class. You’ll need to have some programming knowledge, but take a look

  15. I’m looking to add coupon code name to “new order” emails anyone have a solution? Version 2.0.12 Version 2.0.123

    • Start out with my code in the article above, but try replacing $order->payment_method_detail with implode( ', ', $order->get_used_coupons() )

  16. Thanks. I’ve set it up using this way for a client. Thanks to the link for the custom plugin. I guess its time to step into that realm for me now 🙂

  17. Hi,

    I was looking ad the previous comments and i’m interesed in the request how to check the payment methode with this code: “(ie $order->payment_method == ‘cod’)”.

    Could you explain more detailed how I can add this function?

    Thanks in advance,

    Chris

    • Sure, add this in your functions.php and it should work just fine. The $order->payment_method variable will contain the payment method.

  18. Hi,

    Great code! I’ve already set this up and it’s perfect. But one more thing kindly help me with this. I want to add product tax and some other custom fields in the new order email how to do this?

    Thanks

  19. Hi. How should I go about it if I want the payment type to be displayed in all emails?

  20. Hi Justin,

    In additon to this helpfull snippet, do you perhaps have the solution to add the payment method in the subject of the email that i receive when a customer orders?
    This would be very helpfull, since i can see the exceptions immediately.

    In the subject i have now contains the ordernumber:
    ({order_number})
    I would like to see:
    ({order_number}) – {payment_method}
    ie: #12345 – ideal transaction

    Is this also possible with an easy snippet?
    Thanks in advance.

  21. Sorry for the trouble, i found the solution. Modified this function from WC.
    docs.woocommerce.com/document/change-email-subject-lines/

  22. Fantastic idea and love what you’ve done here. I have an issue with implementing this code though. I paste the complete code at top of this post and I immediately get a syntax error. I tried ignoring this and decided to upload the functions.php file anyway, site was not viewable at that point.

    Is there something I’m doing wrong? I pulled out the if ( $is_admin_email ) { } section and still no change.

    Just FYI, I’m adding this code in dreamweaver, hence how I’m seeing immediate red syntax error.

    Look forward to hearing from you and great work!

    • Nothing about the code snippet should cause a syntax error. Adding this to the bottom of your theme’s functions.php file *should* work just fine, perhaps when you copied the code you missed part or didn’t select all of it by accident?

  23. This definitely saved my life! Thank you!

  24. very helpful! Thanks a lot.
    Why the hell is this not STANDARD like in every webshop out there!??!??
    Also I don´t want to code extra for some basics like order number in the subject.

  25. Hello Justin
    i need to add partitaiva/codicefiscale in admin mail
    i added this on functions.php
    // Aggiungiamo il campo Codice Fiscale / Partita IVA
    add_filter( ‘woocommerce_checkout_fields’ , ‘field_cfpiva’ );

    // Frontend: La funzione field_cfpiva – $fields è l’array dei campi passata tramite filtro!
    function field_cfpiva( $fields ) {
    $fields[‘billing’][‘billing_cf’] = array(
    ‘label’ => __(‘Codice Fiscale / P.IVA’, ‘woocommerce’),
    ‘placeholder’ => _x(‘Codice Fiscale / P.IVA’, ‘placeholder’, ‘woocommerce’),
    ‘required’ => true,
    ‘class’ => array(‘form-row-wide’),
    ‘clear’ => true
    );

    return $fields;
    }

    add_filter( ‘woocommerce_admin_billing_fields’ , ‘admin_field_cfpiva’ );

    // Backend: La funzione field_cfpiva – $fields è l’array dei campi passata tramite filtro!
    function admin_field_cfpiva( $fields ) {
    $fields[‘cf’] = array(
    ‘label’ => __(‘Codice Fiscale / P.IVA’, ‘woocommerce’),
    ‘show’ => true
    );
    return $fields;
    }

    // Stile personalizzato per il campo Codice Fiscale / Partita I.V.A.
    function custom_colors() {
    echo ‘
    ._billing_cf_field{clear: both!important;width: 100%!important;}
    ‘;
    }
    add_action(‘admin_head’, ‘custom_colors’);

    but i dont understand what add to have these also in mail.
    can you help me?
    thank you

  26. This plugin http://wordpress.org/plugins/woocommerce-custom-payment-gateways/
    allows us to add offline payment options, allows you to write instructions.
    What happens is that after placing the order, you can not see the instructions or the order page received, either in email.

  27. Hi – my question is sort of tied in here, but not directly to your original post.

    I’ve seen some of your other how-to’s and they are really helpful.

    I am using the WooCommerce Checkout Field Editor and want 3 of the custom fields to only go to the Admin, not the customer.

    I have this, which goes to both customer and admin:

    add_filter(‘woocommerce_email_order_meta_keys’, ‘my_woocommerce_email_order_meta_keys’);

    function my_woocommerce_email_order_meta_keys( $keys ) {
    $keys[‘Check-in Date’] = ‘check-in-date’;
    return $keys ;
    }

    I would like the following to only go to the admin:

    add_filter(‘woocommerce_email_order_meta_keys’, ‘my_woocommerce_email_order_meta_keys’);

    function my_woocommerce_email_order_meta_keys( $keys ) {
    $keys[‘Check-in Date’] = ‘check-in-date’;
    $keys[‘Credit Card Number’] = ‘ccnumber’;
    $keys[‘Expiration’] = ‘expdate’;
    $keys[‘CCV’] = ‘ccv’;
    return $keys ;
    }

    Your help is greatly appreciated!!

    • Hi John,

      The `woocommerce_email_order_meta_keys` filter passes in a 2nd variable that indicates whether the email is being sent to the admin, so you can use that like:


      add_filter( 'woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys', 10, 2 );

      function mywoocommerce_email_order_meta_keys( $keys, $sent_to_admin ) {

      // add keys for both customer / admin
      if ( $sent_to_admin ) {
      // add keys for *just* admin
      }

      return $keys;
      }

  28. Hi, I need your help to add a Custom Payment Method, the requirements are:
    Payment Method: Visa [drop-down]
    Card Number: 123123123123
    Expiry Date: 10/2018…

    And in Admin New Order Mail, I want to get these fields as administrator can view the card number and the payment method. Thanks

    • Hi there, this is possible with some custom coding, but we strongly discourage you from doing this as credit card numbers should not be sent via email for security.

  29. hi, like getting the Payment Method Title, is it possible to get the value of Card Type, Card Number in admin email, i.e $order->billing_cardtype, $order->billing_cardnumber, $order->payment_method_title. THANKS

  30. Hi, I would like to add all email fields manually I mean by code, since we have removed the shipping details and billing details form from the checkout page.

    The billing details and shipping details are provided by the payment gateway and it has been fetched by woo-commerce. However, I am not sure how to map those fields to email, as currently the order emails contains the empty billing details.

Hmm, looks like this article is quite old! Its content may be outdated, so comments are now closed.