2

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

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?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Gore
  • 163
  • 2
  • 16

1 Answers1

3

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

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

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Thanks you, it is working. But only if status is set to order-accepted and I chose from drop-down (send order emails) "Processing order", mishmashed email arrived. Subject is set to original again (any change is accepted). I also used same condition in email template to change email text (text after heading), which is in this situation set to order-accepted version. I know that combination Order accepted and send processing email is not right combination, but it can happen. Should it be expanded to `if ( $order->has_status('order-accepted') && ! $order->has_status('processing-order') )` ? – Gore Aug 02 '18 at 10:00
  • Hm, no, it doesnt work, Ive tried every statement combination :-) like ||, &&,!. *Thanks you very much I appreciate it, I dont have skype, but I have slow PC :-), I found you on FB, if it is right for you (?) .-)* – Gore Aug 02 '18 at 11:05
  • @Gore Better contact me through my profile linked contact form and I will send you different ways to contact me. – LoicTheAztec Aug 02 '18 at 11:14