WooCommerce 中不存在 wc_order_email 类或函数,因此我更新了您的问题。
您正在查看的是$email 变量参数(WC_Email 当前类型对象)。它主要在模板和钩子中到处定义。
要获取可用的当前电子邮件 ID 作为变量,您只需使用 $email_id = $email->id...
要获取自定义电子邮件的当前电子邮件 ID,您应该使用此代码(仅用于测试):
add_action( 'woocommerce_email_order_details', 'get_the_wc_email_id', 9, 4 );
function get_the_wc_email_id( $order, $sent_to_admin, $plain_text, $email ) {
// Will output the email id for the current notification
echo '<pre>'; print_r($email->id); echo '</pre>';
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。
您将获得以下信息:
new_order
customer_on_hold_order
customer_processing_order
customer_completed_order
customer_refunded_order
customer_partially_refunded_order
cancelled_order
failed_order
customer_reset_password
customer_invoice
customer_new_account
customer_note
一旦您为自定义电子邮件通知获得正确的电子邮件 ID slug,您就可以在任何以下挂钩上使用它(而不是覆盖电子邮件模板):
• woocommerce_email_header (2 个参数:$email_heading、$email)
• woocommerce_email_order_details (4 个参数:$order、$sent_to_admin、$plain_text、$email)
• woocommerce_email_order_meta (4 个参数:$order、$sent_to_admin、$plain_text、$email)
• woocommerce_email_customer_details (4 个参数:$order、$sent_to_admin、$plain_text、$email)
• woocommerce_email_footer (1 个参数:$email)
这里是一个代码示例,我只针对“新订单”电子邮件通知:
add_action( 'woocommerce_email_order_details', 'add_custom_text_to_new_order_email', 10, 4 );
function add_custom_text_to_new_order_email( $order, $sent_to_admin, $plain_text, $email ) {
// Only for "New Order" email notifications (to be replaced by yours)
if( ! ( 'new_order' == $email->id ) ) return;
// Display a custom text (for example)
echo '<p>'.__('My custom text').'</p>';
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。
经过测试并且有效。