• Resolved kwebdesign

    (@kwebdesign)


    I’m trying to update the “Reply To” email address on the “Your Order {Order Number} is Cancelled” email.

    On the “Your {Company Name} order has been received!” email, the “Reply To” address is using the email configured in WooCommerce / Settings / Emails. This is the email I want to use.

    When the customer receives the “Your Order {Order Number} is Cancelled” email, a “Reply To” address isn’t included, so if they click reply, the “To” field is populated with the “From” email address, which has been set in the WP Offload SES plugin settings. I don’t want to change this, as it would effect others emails within the site.

    I’ve tried the following…

    add_filter('wp_mail', 'customize_woocommerce_reply_to_address');
    
    function customize_woocommerce_reply_to_address($args){
        if (isset($args['headers']) && is_array($args['headers'])) {
            foreach ($args['headers'] as &$header) {
                if (strpos($header, 'X-WC-Order') !== false) {
                    if (strpos($args['message'], 'has been cancelled') !== false) {
                        $new_reply_to_address = '[email protected]';
                        $header = 'Reply-to: ' . $new_reply_to_address;
                        break;
                    }
                }
            }
        }
        return $args;
    }
    

    Attempt 2…

    add_filter('aws_ses_wp_mail_modify_message', 'customize_woocommerce_reply_to_address_ses', 10, 3);
    
    function customize_woocommerce_reply_to_address_ses($message_args, $to, $message){
        if (isset($message_args['subject']) && strpos($message_args['subject'], 'is Cancelled') !== false) {
            $new_reply_to_address = '[email protected]'; 
            $message_args['headers'][] = 'Reply-to: ' . $new_reply_to_address;
        }
        return $message_args;
    }
    

    Attempt 3…

    add_filter('aws_ses_wp_mail_modify_message', 'customize_woocommerce_reply_to_address_ses', 10, 3);
    
    function customize_woocommerce_reply_to_address_ses($message_args, $to, $message) {
        if (isset($message_args['subject']) && strpos($message_args['subject'], 'is Cancelled') !== false) {
            $new_reply_to_address = '[email protected]';
            
            if (is_array($message_args['headers'])) {
                $message_args['headers'][] = 'Reply-To: ' . $new_reply_to_address;
            } else if (is_string($message_args['headers'])) {
                $message_args['headers'] = explode("\r\n", $message_args['headers']);
                $message_args['headers'][] = 'Reply-To: ' . $new_reply_to_address;
            }
        }
        return $message_args;
    }
    

    Attempt 4…

    add_filter( 'woocommerce_email_headers', 'customize_wc_email_headers', 10, 3 );
    
    function customize_wc_email_headers( $headers, $email_id, $order ) {
        if ( $email_id === 'cancelled_order' ) {
            $headers .= 'Reply-to: [email protected]' . "\r\n";
        }
        return $headers;
    }
    

    Attempt 5…

    add_filter( 'woocommerce_email_headers', 'change_reply_to_email_address', 10, 4 );
    
    function change_reply_to_email_address( $header, $email_id, $order, $email ) {
          $reply_to_name  = 'New Email';
          $reply_to_email = '[email protected]';
          $header  = "Content-Type: " . $email->get_content_type() . "\r\n";
          $header .= 'Reply-to: ' . $reply_to_name . ' <' . $reply_to_email . ">\r\n";
          return $header;
    }

    If anyone knows how to achieve this, your input would be greatly appreciated.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support con

    (@conschneider)

    Engineer

    Howdy,

    Attempt 6:

    function custom_cancelled_order_email_reply_to( $headers, $email_id, $order ) {
        // Check if the email is for cancelled order
        if ( 'customer_cancelled_order' === $email_id ) {
            // Replace this with your email
            $reply_to_email = '[email protected]';
            // Add the 'Reply-To' header
            $headers .= 'Reply-To: ' . $reply_to_email . '\r\n';
        }
    
        return $headers;
    }
    
    add_filter( 'woocommerce_email_headers', 'custom_cancelled_order_email_reply_to', 10, 3 );
    ?>

    This should take care of the reply-to. Afterwards you can write a function that gets the setting from the SES plugin and replace the string for $reply_to_email.
    ??

    Kind regards,

    Thread Starter kwebdesign

    (@kwebdesign)

    Apologies for the delay responding and many thanks for your input.

    Unfortunately, I’ve just tested this snippet and the email received, still didn’t include a Reply To address.

    The 1st email with a subject of “Your {Company Name} order has been received!” did.
    The 2nd email with a subject of “Your Order {123456} is Cancelled” did not.

    Plugin Support con

    (@conschneider)

    Engineer

    Hi again,

    I made a mistake with the mail ID.

    Attempt 7:

    
    function custom_cancelled_order_email_reply_to( $headers, $email_id, $order ) {
        // Check if the email is for cancelled order. For real this time. 
        if ( 'cancelled_order' === $email_id ) {
            // Replace this with your email
            $reply_to_email = '[email protected]';
            // Add the 'Reply-To' header
            $headers .= 'Reply-To: ' . $reply_to_email . '\r\n';
        }
    
        return $headers;
    }
    
    add_filter( 'woocommerce_email_headers', 'custom_cancelled_order_email_reply_to', 10, 3 );
    

    Could you try one more time?

    Kind regards,

    Thread Starter kwebdesign

    (@kwebdesign)

    Still no luck, but thanks again for trying.

    Plugin Support con

    (@conschneider)

    Engineer

    Sure thing. I am afraid I am out of ideas for now.
    Leaving this thread open in case anybody else can provide input.

    Kind regards,

    Thread Starter kwebdesign

    (@kwebdesign)

    As an alternative solution, I’d now like to try editing the body copy of this email, to include the preferred Reply To address.

    However, this particular email doesn’t appear under WooCommerce / Settings / Emails or within the WooCommerce email template files.

    I guess the most common template used for a customer, when an order is cancelled, would be the “Refunded order” email. With the “Direct bank transfer” payment option, this isn’t relevant, hence the use of this fallback email.

    I’ve tried the following…

    add_action( 'woocommerce_email_before_order_table', 'add_email_content', 10, 4 );
    
    function add_email_content( $order, $sent_to_admin, $plain_text, $email ) {
       if ( 'cancelled' === $order->get_status() && 'customer' === $email->role && 'yes' === $email->enabled ) {
          echo '<p>This is some additional content for the cancelled order email.</p>';
       }
    }
    

    This didn’t work.

    Is anyone able to tell me how I can edit the content that is included in this email?

    Thread Starter kwebdesign

    (@kwebdesign)

    Just a little update…

    I’ve just set up a completely blank install of WordPress.
    I’ve installed WooCommerce with “Direct Bank Transfer” enabled and a dummy test product. I’ve also set up email functionality with WP Offload SES.

    Having placed a test order, I received the “Your {Website Name} order has been received!”, but once the order was cancelled, I didn’t receive the “Your Order {123456} is Cancelled” email. This suggests that it’s possibly another plugin generating this email. If so, I would have thought someone at WooCommerce would have picked up on this and mentioned it.

    In the meantime, I’ll look at cloning the original site and repeating the test, whilst removing one plugin at a time, to see if the email suddenly stops arriving.

    Thread Starter kwebdesign

    (@kwebdesign)

    I’ve just discovered that the email is being generated via the Shop Magic plugin, so I apologise for wasting the time of anyone who has viewed this thread.

    Thanks again to those who offered their assistance.

    Plugin Support Beauty of Code (woo-hc)

    (@beautyofcode)

    Hi @kwebdesign ,

    Glad to hear that you managed to find the plugin generating the email!

    Since this has been resolved, feel free to?create a new topic?if you need any further help.?

    Also, if you have a minute, we’d love it if you would leave us a review:

    https://www.ads-software.com/support/plugin/woocommerce/reviews/

    Cheers!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Change Reply To on Your Order Is Cancelled Email’ is closed to new replies.