Add an order note to customers when they approve their orders in WooCommerce

Viewed 726

In WooCommerce, Allow customer to change order status in WooCommerce answer to my previous question, allows the customer to approve (complete) orders in "My Account" page, but I don't know how to add a note automatically, so when the Customer approves an order (order status is changed to completed), I want to automatically add a note for customer.

Is it possible to add a Note when customer approve an order and status is changed to "completed"?

1 Answers

If you want an order note for the customer, replace the following code line:

        // Change order status to "completed"
        $order->update_status( 'completed', __('Approved by the customer', 'woocommerce') ) ;

by:

        // Add an order note for the customer (blue background note in admin orders)
        $order->add_order_note( __('You have approved this order on', 'woocommerce') . ' ' . date_i18n( 'F j, Y' ), true );

        // Change order status to "completed"
        $order->update_status( 'completed', __('Approved by the customer', 'woocommerce') ) ;

WooCommerce Documentation: WC_Order method add_order_note()

Related