我已成功更改Woocommerce处理订单(使用this thread)的电子邮件主题:
add_filter( 'woocommerce_email_subject_customer_processing_order', 'email_subject_procs_order', 10, 2 );
function email_subject_procs_order( $formated_subject, $order ){
return sprintf( esc_html__( 'Example of subject #%s', 'textdomain'), $order->get_id() );
}
但是我想在订单状态更改后再次发送带有新主题的处理订单电子邮件,因此我按照this tread来调整主题等。
add_action('woocommerce_order_status_order-accepted', 'backorder_status_custom_notification', 20, 2);
function backorder_status_custom_notification( $order_id, $order ) {
// HERE below your settings
$heading = __('Your Awaiting delivery order','woocommerce');
$subject = sprintf( esc_html__( 'New subject #%s', 'textdomain'), $order->get_id() );
// Getting all WC_emails objects
$mailer = WC()->mailer()->get_emails();
// Customizing Heading and subject In the WC_email processing Order object
$mailer['WC_Email_Customer_Processing_Order']->heading = $heading;
$mailer['WC_Email_Customer_Processing_Order']->settings['heading'] = $heading;
$mailer['WC_Email_Customer_Processing_Order']->subject = $subject;
$mailer['WC_Email_Customer_Processing_Order']->settings['subject'] = $subject;
// Sending the customized email
$mailer['WC_Email_Customer_Processing_Order']->trigger( $order_id );
}
但仅接受第一个电子邮件主题更改。有办法让它一起工作吗?
if( $order->has_status( 'order-accepted' ))
是否有权使用?
答案 0 :(得分:1)
您需要在 IF
语句中使用自定义状态,以通过以下方式避免该问题:
add_filter( 'woocommerce_email_subject_customer_processing_order', 'email_subject_procs_order', 10, 2 );
function email_subject_procs_order( $formated_subject, $order ){
// We exit for 'order-accepted' custom order status
if( $order->has_status('order-accepted') )
return $formated_subject;
return sprintf( esc_html__( 'Example of subject #%s', 'textdomain'), $order->get_id() );
}
代码进入您的活动子主题(或活动主题)的function.php文件中。应该可以。