wc_create_order_note()WC 3.2.0

Create an order note.

No Hooks.

Return

Int|WP_Error. Integer when created or WP_Error when found an error.

Usage

wc_create_order_note( $order_id, $note, $is_customer_note, $added_by_user );
$order_id(int) (required)
Order ID.
$note(string) (required)
Note to add.
$is_customer_note(true|false)
If is a costumer note.
Default: false
$added_by_user(true|false)
If note is create by an user.
Default: false

Changelog

Since 3.2.0 Introduced.

wc_create_order_note() code WC 8.7.0

function wc_create_order_note( $order_id, $note, $is_customer_note = false, $added_by_user = false ) {
	$order = wc_get_order( $order_id );

	if ( ! $order ) {
		return new WP_Error( 'invalid_order_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 400 ) );
	}

	return $order->add_order_note( $note, (int) $is_customer_note, $added_by_user );
}