I have custom statuses and custom emails set up in Woocommerce. I would like to use the current email, WC_Email
, not the current status as a variable inside email templates.
I need to have some if statements in the email templates. I am not using the order status to ensure if an email from an order gets resent manually it doesn't send data for the current order status with an separate email.
How can I echo the WC_Email
email ID as a variable in Woocommerce?
The
wc_order_email
class or function doesn't exist in WooCommerce, so I have updated your question.What you are looking at is
$email
variable argument (theWC_Email
current type object). It's mostly defined everywhere in templates and hooks.To get the usable current Email ID as a variable you will simply use
$email_id = $email->id
…To get the current Email ID of your custom emails, you should use this code (just for testing):
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Once you get the correct email ID slug for your custom email notification you can use it on any following hook (instead of overriding email templates):
•
woocommerce_email_header
(2 arguments:$email_heading
,$email
)•
woocommerce_email_order_details
(4 arguments:$order
,$sent_to_admin
,$plain_text
,$email
)•
woocommerce_email_order_meta
(4 arguments:$order
,$sent_to_admin
,$plain_text
,$email
)•
woocommerce_email_customer_details
(4 arguments:$order
,$sent_to_admin
,$plain_text
,$email
)•
woocommerce_email_footer
(1 argument:$email
)HERE an example of code where I target "New order" email notifications only:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works.