WC_API_Orders::get_order_notes()publicWC 2.1

Get the admin order notes for an order

Method of the class: WC_API_Orders{}

Hooks from the method

Return

Array|WP_Error.

Usage

$WC_API_Orders = new WC_API_Orders();
$WC_API_Orders->get_order_notes( $order_id, $fields );
$order_id(string) (required)
order ID
$fields(string|null)
fields to include in response
Default: null

Changelog

Since 2.1 Introduced.

WC_API_Orders::get_order_notes() code WC 8.7.0

public function get_order_notes( $order_id, $fields = null ) {

	// ensure ID is valid order ID
	$order_id = $this->validate_request( $order_id, $this->post_type, 'read' );

	if ( is_wp_error( $order_id ) ) {
		return $order_id;
	}

	$args = array(
		'post_id' => $order_id,
		'approve' => 'approve',
		'type'    => 'order_note',
	);

	remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );

	$notes = get_comments( $args );

	add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );

	$order_notes = array();

	foreach ( $notes as $note ) {

		$order_notes[] = current( $this->get_order_note( $order_id, $note->comment_ID, $fields ) );
	}

	return array( 'order_notes' => apply_filters( 'woocommerce_api_order_notes_response', $order_notes, $order_id, $fields, $notes, $this->server ) );
}