1
votes

I am trying to cancel/remove the automatic customer emails that are sent when saving order status as "completed" after the order was shipped.

The reason for not wanting automatic emails to be sent is because I added a a code to the email template file (override) /woocommerce/email/customer-completed-order.php which will display the new order note created in the admin in the email sent to the customer and if we add the order note and save it and then change the order status to completed and save it, a new note is created and an email is sent. So now the note showing in the email sent to the customer is not the note that we wanted to display in the email. The entire intention of this is to have a nicely designed email with status update "shipped" and include the tracking number of the shipment. The code that adds the last/newest order note to the email:

<?php
$args = array(
'status' => 'approve',
'post_id' => $order->id
);
$comments = get_comments($args);
foreach($comments as $comment) {
if ($comment === reset ($comments))
echo $comment->comment_content . '.<br />';
}

So I now found a solution for this. Adding the function from this link: https://docs.woocommerce.com/document/unhookremove-woocommerce-emails/

add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );

function unhook_those_pesky_emails( $email_class ) {

remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
}

The above function will disable the automatic email that is sent when saving the order with the status "completed" but you can still manually send the order completed email using the "order actions" and control which last order note is saved while sending the email. So now we simply change the order status to completed and save, then we add an "order note to customer" (not private) which only contains the tracking number and save it ("add note") and lastly we use the "order actions" to manually send the order completed email to the customer.

Feel free if any questions...

3
Can you add the tracking numbers dynamically or do you have to manually type the code on each email?Gert-Jan Kooijmans
This code was added to the override of the template file /woocommerce/email/customer-completed-order.php. So I am only adding the tracking number as a customer note, and while it is the last note saved I can manually send the completed order email.eavinu
Update your answer with all related code (that function you have added… and other related customizations) and try to be more clear and logical (please). May be this way someone is going to be able helping you…LoicTheAztec

3 Answers

1
votes

The entire intention of this is to have a nicely designed email with status update "shipped" and include the tracking number of the shipment.

I recommend creating your own order status and calling it shipped. Here's how to make it all work: WooCommerce - send custom email on custom order status change

0
votes

I had a similar issue but resolved it differently:

We disabled the automatic email that is sent once the order is completed (in WC>settings>emails) so no email is sent out when the order is marked completed.

We then changed the email template of the order notes to our desired text (e.g. "Your order has now been completed and is on it's way to you. Please find below the tracking numbers for your shipment") and use the note function for the tracking numbers. They don't link to the tracking website directly but with the shipping agents detailed provided in the template it should be easy for the customer to manually copy and paste for tracking.

Would that work for you?

0
votes
<?php
  $args = array(
   'status' => 'approve',
   'post_id' => $order->id
   );
  $comments = get_comments($args);
  foreach($comments as $comment)          
   {
     if ($comment === reset ($comments))
        echo $comment->comment_content . '.<br />';
   }

The above code does not give the desired output(i.e. the last order note to the customer) in WooCommerce(WC) 3.1.0

The working of the above code was due to a bug which was fixed in WC 3.1.0. For the above code to work(to return the last order note to the customer) do the following: remove the code line: $comments = get_comments($args); and replace it with:


`remove_filter( 'comments_clauses', array( 'WC_Comments','exclude_order_comments' ), 10, 1 );
 $comments = get_comments( $args );
 add_filter( 'comments_clauses', array( 'WC_Comments','exclude_order_comments' ), 10, 1 );`

Fo more details on the bug :https://github.com/woocommerce/woocommerce/issues/15982#issuecomment-313235066