WooCommerce add order note programmatically

To add a custom order note programmatically with the WooCommerce order, which will show on the admin order details page, we need to add an order note when a user has completed the WooCommerce checkout process. We can do this using the ‘woocommerce_thankyou’ action hook like the one below:

function add_custom_order_notes( $order_id ) {
	
	$order = wc_get_order(  $order_id );
	
	// Text for the note
	$note = __("This is my test note", 'text-domain');

	// Add note
	$order->add_order_note( $note );
}; 

add_action( 'woocommerce_thankyou', 'add_custom_order_notes', 10, 1 ); 

When the user completes the checkout process, the user is redirected to the WooCommerce thank you page, and then an action hook named woocommerce_thankyou is run. So the attached callback functions with that action hook can perform some tasks, as I showed above. First, it calls the wc_get_order( $order_id ) function to get the $order object and then calls a function name add_order_note() associated with that $order object to add the order note.

In the order details page right sidebar area on the admin screen, you can see the order note likes below :

Order note

Leave a Reply

Your email address will not be published. Required fields are marked *