I would like to get the recipients field value from WooCommerce emails settings for "New Order" email as shown below:
How to get Recipient(s) field? Any help is appreciated.
You can do it using the following simple line:
WC()->mailer()->get_emails()['WC_Email_New_Order']->recipient;
// Or: WC()->mailer()->get_emails()['WC_Email_New_Order']->get_recipient();
// Or: WC()->mailer()->get_emails()['WC_Email_New_Order']->settings['recipient'];
Or in details (code is commented):
// Get an instance of the WC_emails Object
$wc_emails = WC()->mailer();
// Get available emails notifications
$emails_array = $wc_emails->get_emails();
// Get the instance of the WC_Email_New_Order Object
$new_order_email = $emails_array['WC_Email_New_Order'];
// Get recipients from New Order email notification
$new_order_recipient = $new_order_email->recipient;
// Or $new_order_email->get_recipient();
// Or $new_order_email->settings['recipient'];
The Class
WC_Email_New_Order
is "An email sent to the admin when a new order is received / paid for" (as you can see on the docs).The
WC_Email
methodget_recipient()
use in it's source code$this->recipient
where$this
is theWC_Email_New_Order
Object in this case (as it extends theWC_Email
Class).You can use either the method
get_recipient()
, the propertyrecipient
orsettings['recipient']
.