Posted on

WooCommerce Visual Hook Guide: Emails

WooCommerce Customizers: the Visual Hook Guide is back πŸ™‚

Here’s a visual HTML hook guide for the WooCommerce Emails. This visual guide belongs to my “Visual Hook Guide Series“, that I’ve put together so that you can find WooCommerce hooks quickly and easily by seeing their actual locations.

Let me know in the comments if this resource it’s helpful and how! Also, if you’re eager to learn how to use this guide, how to customize emails AND how to make sure your customization only affects one email type (e.g. only the Customer Processing email), take a look at this free video lesson.

Enjoy πŸ™‚

WooCommerce Email Hooks

New customer order

woocommerce_email_header ($email_heading, $email)

You have received an order from fdgfg dfgfdg. The order is as follows:

woocommerce_email_order_details ($order, $sent_to_admin, $plain_text, $email)woocommerce_email_before_order_table ($order, $sent_to_admin, $plain_text, $email)

Order #19950 ()

Product Quantity Price
Simple Product
woocommerce_order_item_meta_start($item_id, $item, $order, $plain_text)
woocommerce_order_item_meta_end ($item_id, $item, $order, $plain_text)
1 €180.49(ex. VAT)
Subtotal: €180.49(ex. VAT)
Shipping: Free Shipping
Tax: €41.51
Payment Method: Direct Bank
Transfer
Total: €222.00

woocommerce_email_after_order_table ($order, $sent_to_admin, $plain_text, $email)woocommerce_email_order_meta ($order, $sent_to_admin, $plain_text, $email)woocommerce_email_customer_details ($order, $sent_to_admin, $plain_text, $email)

Customer details

  • Email: test@test.com
  • Tel: 345435

Billing address

Rodolfo Melogli
dfgdfg
dfgdfg
dfgfdgfg
00000
ghsfghgfh

Shipping address

Rodolfo Melogli
dfgdfg
dfgdfg
dfgfdgfg
00000
ghsfghgfh

woocommerce_email_footer($email)

WooCommerce Email Default add_actions


// --------------------------------------
// These are actions you can unhook/remove!
// You must pass $object to the function
// e.g. function remove_header( $object ) {
//   remove_action....
// }
// --------------------------------------

// Email Header, Footer and content hooks
		
add_action( 'woocommerce_email_header', array( $object, 'email_header' ) );
add_action( 'woocommerce_email_footer', array( $object, 'email_footer' ) );
add_action( 'woocommerce_email_order_details', array( $object, 'order_details' ), 10, 4 );
add_action( 'woocommerce_email_order_details', array( $object, 'order_schema_markup' ), 20, 4 );
add_action( 'woocommerce_email_order_meta', array( $object, 'order_meta' ), 10, 3 );
add_action( 'woocommerce_email_customer_details', array( $object, 'customer_details' ), 10, 3 );
add_action( 'woocommerce_email_customer_details', array( $object, 'email_addresses' ), 20, 3 );

// Hooks for sending emails during store events
		
add_action( 'woocommerce_low_stock_notification', array( $object, 'low_stock' ) );
add_action( 'woocommerce_no_stock_notification', array( $object, 'no_stock' ) );
add_action( 'woocommerce_product_on_backorder_notification', array( $object, 'backorder' ) );
add_action( 'woocommerce_created_customer_notification', array( $object, 'customer_new_account' ), 10, 3 );

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

51 thoughts on “WooCommerce Visual Hook Guide: Emails

  1. Hello Mr. Melogli

    I was hoping you might be able to help me:
    The image https://imgur.com/7WtDW8u displays an issue: “Undefined variable: email in /usr/www/mytowqvypx/wp-content/themes/towerlabels/woocommerce/emails/customer-order-status-email.php on line 65”

    Does that mean that the issue is limited to $email or every do_action(~); that contains it?

    Your assistance is most appreciated.
    Thank you and Kind Regards
    Luan

    1. Hey Luan πŸ™‚ The issue is with your theme, you need to update it or switch to another one.

  2. Hi Rodolfo!
    I want erase the link “View my bookings β†’” of the email that receive the client.
    Just this link.
    I donΒ΄t know how do it.
    Can you help me?

    1. Hello Ulises- thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  3. Hi Rodolfo, Fantastic guide – thank you!

    I have a question. Orders with both downloadable and shipped products show these in two distinct tables; are there hooks to only target the ‘downloadable’ items table? I’ve scoured the code but I feel like I’m missing something. Thanks for all your great content!

    1. Hey Lionel, thanks for your message! The only ones I could find are:

      woocommerce_email_downloads_column_1
      woocommerce_email_downloads_column_2
      // etc.
      

      Not sure if this helps πŸ™‚

  4. dear Sir.
    please help me i want to add product weight at bottom of product title in woo-commerce emails.

    1. Hi there, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  5. Can you guide me how to send cancel emails to customers, and let them know that there email are the cancel with the reason

    1. Hey Abdul, thanks so much for your comment! You can enable cancel order email notifications from the WooCommerce settings πŸ™‚

  6. Hi, if we have to add text we have no option but to edit the template ( of course by copying the template into the child theme ) ? or is there a way to achieve the above with hooks?

    1. Hi Srikanth, thanks so much for your comment! It depends where you need to print it πŸ™‚

  7. I have added som extra content with the use of “woocommerce_order_item_meta_end”

    But I see the message on all email templates.
    How to only show the content on the “Completed order” template ?

    1. Hey Simon, thanks for your comment! Section #4 of my video tutorial should help you achieve just that: https://businessbloomer.com/customize-emails-woocommerce/. Hope this helps

  8. Hi!

    Can I add email for new user notification?

    When a new customer sign in even if he did not make an order, I would like to get a notification email.
    (the recipient now is only the customer)
    Is that possible and how ?

    any suggestion will be great πŸ˜€
    thanks in advanced

    1. Hey Natalia, thanks for your comment! I believe you can add multiple email recipients to the same email, give it a go πŸ™‚

  9. Hi, it is possible to make a hook, where the email that is sent to the customer after making a purchase (customer-on-hold-order.php.) Also reaches an email that I define?

    1. Francisco, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  10. Hi Rodolfo is possible hide billing_company field from emails?

    1. Hey Mattia, thanks for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  11. Hi,

    First I would like to say that you have a very important site.
    Thank you for all the tutorials.
    Few questions:
    ———————
    How can I:
    1. Add the regular price above the price (with strike through)?

    2. Add the total discount for the order in woocommerce_email_after_order_table?

    Thank you,

    Sam

    1. Hey Sam, thanks for your comment! I can’t help I’m afraid as it is custom work, however have you watched my tutorial yet: http://businessbloomer.com/customize-emails-woocommerce/?

  12. Hi Rodolfo

    I wanted to add a footer image to my e-mail template. Is this complicated?

    Thanks
    James

    1. Hey James thanks for your comment! No, it’s not complicated, as long as you understand minimal HTML and PHP. Take a look at this video tutorial, hopefully it can help together with my visual hook guide: businessbloomer.com/customize-emails-woocommerce/

  13. Hi, I have found it before but can’t find it anymore: where do we customize the code? (which file?)
    Thanks, Agnes

    1. Hey Agnes, thanks for your comment! You can place your customization in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: http://businessbloomer.com/woocommerce-customization-hangout/. Hope this helps!

  14. Hi Rodolfo, what a great info here in your awesome blog.

    I want to ask you if there is any way to hide/delete the prices row in this email

    thanks a lot

    1. Thank you so much David!!! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  15. I am new to all of this, but with your help I have been able to accomplish quite a few things. I am having a bit trouble of adding the product images to the email notifications. Is there a snippet or code for that function to work?

    1. Hello LaToya, thanks so much for your comment! Yes, this is possible, but unfortunately I don’t have a snippet for that and I cannot provide a complementary solution here on the blog. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  16. Thanks for this, one of the easiest tutorials to follow that I have seen πŸ™‚

    1. Awesome, thanks Stewart!

  17. Hi Rodolfo, i’m looking for a way to put, in the new order email, the product variation description (the one appears here when you choose a box type… (https://www.naranjascostadelsol.es/tienda-de-naranjas-online/naranjas-de-mesa-mandarinas-y-aguacates/).

    I spent a lot of hour to look for something valid but …no way…still searching… but now i fond your post here…and it seems i should work on woocommerce_order_item_meta_start… but i have no php skill…so do you have a snippet to do it?

    Thank you very much
    Angelo

    1. Angelo, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide you with a complementary solution here on the blog. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  18. Wow. That’s exactly what I was looking for! Thank you!
    Took me 20 seconds. πŸ˜€

    1. Awesome! Great to hear that Kevin πŸ™‚

  19. HI,
    Is it possible to use hooks/filters to change the text which says: “Your order has been received and is now being processed. Your order details are shown below for your reference:” which appears at the top of the customer processing email?.

    1. Hey Andy, thanks for your comment! There is no filter to change that string, but I would recommend you try with this: https://businessbloomer.com/translate-single-string-woocommerce-wordpress. Let me know if it works!

    2. That looks great I will have to try it.
      I would also ideally like to change the text inside this:

      <?php printf( __( 'Thanks for creating an account on %s. Your username is %s‘, ‘woocommerce’ ), esc_html( $blogname ), esc_html( $user_login ) ); ?>

      which is sent in the new account email.

      I will want to keep the part of the string that dynamically displays the username so the complete new text will look like:

      Many thanks for creating an account with us, we’re delighted you’ve chosen to shop with us.

      Your username is:

      Kindest wishes
      Shop Name

      But will this part of the string:
      %s
      copy/translate over to the new string ok and ?

    3. Andy, with the translation snippet I referenced, you can totally translate “Thanks for creating an account on %s. Your username is %s” as a string. Only thing is that you have to maintain the order of the “%s”, so you will need to mention the shop name before the username.

      Otherwise, You will need to override the whole WooCommerce template.

    4. Brilliant, thanks!

  20. Hey Rodolfo, loved your webinar yesterday, thanks.

    I hope you can point me in the right direction as I can’t find the answer to this anywhere on your site but I’m sure you have probably covered it somewhere.

    On most customer emails there is a table that is headed:

    Product Quantity Price

    and contains rows showing Subtotal & Total.

    Where/how can I edit the table? I need to change the word Product to Event and if possible remove the Subtotal row as it isn’t relevant or required

    Thanks in advance

    1. Hi Rodolfo, just a quick update.

      I found I needed to change the email-order-details.php file for the Table Headings (simply changed the text in my child theme file)

      As for the SubTotal & Total – I removed a block of code from the bottom of the same file:

       <tfoot>
      	<?php
      		if ( $totals = $order->get_order_item_totals() ) {
      			$i = 0;
      			foreach ( $totals as $total ) {
      				$i++;
      				?><tr>
      					<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
      					<td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
      				</tr><?php
      			}
      		}
      	?>
      </tfoot>

      Might help somebody!!

    2. Thanks Mark for updating us! I really hope you haven’t edited the plugin core files, but duplicated email-order-details.php into your child theme’s /woocommerce/emails folder πŸ™‚

      Also, this might have been done without this duplication I believe (remember, duplicating templates should be done only when strictly necessary).

      Cheers and thanks again!

      R

    3. Don’t fret – it wasn’t the core file but in the child theme. Thanks for checking.

    4. Ah, awesome Mark πŸ™‚ Glad about that! Thanks for following up.

  21. Hi,

    Thanks for this very detailed tutorial / guide.

    Is there any way we can add a custom image next to the text where “New customer order” is mentioned?

    Thanks.

    KoolPal

    1. Good question KoolPal!

      You can easily add content above or below, but doing it beside it’s pretty complex as there is no official hook. You might need to override the email-header.php in your child theme (not recommended), or maybe use the filter “woocommerce_mail_content”.

      Let me know if you find anything! I hope you can join us for the WooCommerce Emails Customization Class by the way πŸ™‚

  22. […] handy PHP snippet is therefore the only viable solution. By using the WooCommerce Email Hook Guide, I identified an action called woocommerce_email_header, which is the very first thing that gets […]

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.