本文介绍了在Woocommerce 3中更改电子邮件主题以获取自定义订单状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功更改了Woocommerce处理订单的电子邮件主题(使用 该主题 ):

I have successfully changed email subject for Woocommerce processing order (using 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() );
}

但是我想在订单状态更改后再次发送带有新主题的加工订单电子邮件,因此我遵循了 此步骤 以调整主题等.

But I want send processing order email again with new subject after order status is changed, so I followed this tread to tweak subject etc.

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' ))有权使用吗?

But only first email subject change is accepted. Is there way to get it work together?
Is if( $order->has_status( 'order-accepted' )) right to be used?

推荐答案

您需要在 IF 语句中使用自定义状态,以免出现此问题,方法是:

You need to use your custom status in a IF statement to avoid that problem, this way:

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文件中.应该可以.

Code goes in function.php file of your active child theme (or active theme). It should works.

这篇关于在Woocommerce 3中更改电子邮件主题以获取自定义订单状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 21:58