更改Wooccommerce 3中自定义订单状态的电子邮件主题



我已成功更改Wooccommerce处理订单的电子邮件主题(使用此线程(:

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() );
} 

但我想在订单状态更改后再次发送带有新主题的处理订单电子邮件,所以我遵循此步骤调整主题等。

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' ))是否正确?

您需要在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文件中。它应该有效。

相关内容

最新更新