0

I am working on customizing the woocommerce email templates according to my own needs. I just wanted to know if I can access the current email id (like customer_processing_order, or admin_new_order) so that I can use it in conditional statements like

$email_id = /* Some function to get the email id */

if($email_id == 'admin_new_order') {
//do somthing

}

I want to use it inside email-order-details.php and also inside email-order-items.php

Thanks

Shahid Khattak
  • 69
  • 1
  • 13

1 Answers1

2

Techno Deviser's comment is correct.

Inside email-order-details.php you have a few params available:

$order, $sent_to_admin, $plain_text, $email

$email is an object that consists of order info and much more. I see that id is always available.

So you can do:

$email_id = $email->id;

if($email_id == 'customer_note') {
  // another id i've seen during testing (just now) is: customer_on_hold_order

  //do somthing
}

NOTE: inside email-order-items.php the $email param is not available. For now i'm not really sure how to get some kind of email id in this template, i'll have to investigate more.

Regards, Bjorn

Bjorn
  • 709
  • 1
  • 4
  • 12
  • Thank you very much, I was trying that inside the main template, that's why it was not working. Thanks once again. – Shahid Khattak Jun 09 '18 at 12:15
  • is there a way to get this inside this file /templates/emails/email-order-items.php – Suneth Kalhara Jan 06 '19 at 09:00
  • With a workaround you can first get the ID by using the hook `woocommerce_email_order_details` then process this with a custom or the `woocommerce_order_item_meta_start` hook. – Bjorn Jan 06 '19 at 13:30