WooCommerce add order note programmatically

To add custom order note programmatically in WooCommerce admin order details page, first we need to add a order note when user has completed the WooCommerce checkout process. We can do this using ‘woocommerce_thankyou’ action hook like 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 ); 

Here, when user complete the checkout process, user redirect to the WooCommerce thank you page and then a action hook named woocommerce_thankyou is run. So the attached callback functions with that action hook can perform some kind of a task like i shown above. First it call wc_get_order( $order_id ) function to get $order object and then call a function name add_order_note() associate with that $order object to add the order note.

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

Leave a Reply

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