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...