My Courses > CustomizeWoo > Module 6 > Lesson 03: Add Content to Order Emails
Add Content to Order Emails
You can use this exercise as a test. Stop the video after the project description and see if you can manage to find the PHP solution. Then continue watching the video to watch me code the task.
Video
Please note: English captions are enabled by default (click on “CC” in the video player to disable). Also, you can click on the “gear” icon to manage quality and playback speed. Enjoy!
Sorry, this video is only visible to logged in Business Bloomer Club members with a PRO PASS.
If you joined already, please log in.
Otherwise, here is why you should join the Club.
If you joined already, please log in.
Otherwise, here is why you should join the Club.
Hello, Rodolfo
I would like to know how we can remove content from emails. For example, where should we look to remove these sections from email?
https://www.screencast.com/t/zsPJLgxSpKj
Thank you!
Hi Marcel! The first bit you can’t unfortunately. They are hardcoded into the email template without any hook which would have been useful to remove such content. You could find a workaround i.e. “translate” those strings into empty strings: https://www.businessbloomer.com/translate-single-string-woocommerce-wordpress/
For the other section, that one you can definitely remove it. Simply look at https://www.businessbloomer.com/woocommerce-visual-hook-guide-emails/, find the add_action that is adding that order table, and use remove_action
Hope this helps
Hi Rodolfo,
I try to add some information about a specific product on the email the customer receives. I wrote this code and it’s working, but I would like to know your opinion about how correct it is. Thank you.
Hi Marcel, looks good to me. You don’t need to declare the global, but that’s not throwing an error anyway
For my understanding, when exactly should I declare
?
Thank you!
Posting my code again before watching the rest of the video. 🙂
So it looks like I wasn’t aware that I needed to check for the right order email! Oops. And so we learn.
I also didn’t think about accessing $order via the arguments and did it another way. Rodolfo, are there any pros/cons when looking at the way you got the $order vs the way I did it (other than a line less of code)? It will help me understand better why to do something in a specific way.
Why is better to say true == $sent_to_admin than $sent_to_admin == true?
Thanks so much, useful exercise!
Great questions!
1) Given that you have $order available as a function argument, it’s much faster to use it as opposed to recalculating it from $email
2) “true == variable” is better than “variable == true” because in this way you can avoid PHP errors that can cause issues. If you forget a “=”, which is very common, “true = variable” does nothing and it just returns an error, while “variable = true” assigns the value “true” to your variable, which is going to mess your conditional. So it’s only a way to avoid mistakes. Same applies to “25 == variable” and every “IF a == b” conditional checks
Aaah thanks so much Rodolfo, knowing WHY something should be done a certain way really helps me understand it better.
Hello, I am trying to remove the default woocommerce email header text and replace it with my own custom text. I’ve tried a few methods and nothing has worked so far. I understand how to add new content but to replace it, do I need to first use a remove_action to remove the original text and then use an add_action to replace the content? Thank you
Thanks for your comment Phoebe! Which content are you talking about specifically?
I am talking about the intro paragraph in the header above the order details table. For example on the ‘on-hold’ email I want to replace this default Woocommerce text:
“Thanks for your order. It’s on-hold until we confirm that payment has been received. In the meantime, here’s a reminder of what you ordered:”
That was what I was afraid of. No hook available there (as of now). Your only choice is to “translate” those strings: https://businessbloomer.com/translate-single-string-woocommerce-wordpress/
Okay thank you, I’ll try it out!