如何从 WooCommerce 中的新订单电子邮件中获取电子邮件收件人

How to get email recipients from new order email in WooCommerce

我想从 "New Order" 电子邮件的 WooCommerce 电子邮件设置中获取收件人字段值,如下所示:

如何获取收件人字段?感谢任何帮助。

您可以使用以下简单的行来完成:

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'];

或详细说明(代码有注释):

// 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 method get_recipient() use in it's source code $this->recipient where $this is the WC_Email_New_Order Object in this case (as it extends the WC_Email Class).

You can use either the method get_recipient(), the property recipient or settings['recipient'].