I have a script that changes the status of orders based on our ERP system.
In addition to that, we need to add customer notes. I found the way to do it:
$order->add_order_note($note);
$order->save();
Unfortunately this won't work outside the order edit screen, I tried to run it from my custom plugin. (source)
If I do it via $order->update_status($status, $note); it only updates the status.
Is there a way to add a note outside the edit screen? (Including e-mailing the customer)
If the note is for the customer (and has to be visible for him) you need to use instead the WC_Order method set_customer_note() (or both):
$order->set_customer_note($note);
// $order->add_order_note($note);
$order->save();
Or:
$order->set_customer_note($note);
$order->update_status($status, $note);
This need to be done before saving the order data or updating the order status.
To re-send the email notification to the customer (if needed) you can use from the current order ID:
$emails = WC()->mailer()->get_emails();
$emails['WC_Email_Customer_Completed_Order']->trigger( $order_id );
// OR: $emails['WC_Email_Customer_Processing_Order']->trigger( $order_id );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With