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( $id, $fields );
$id(int) (required)
the order ID
$fields(string)
fields to include in response
Default: null

Changelog

Since 2.1 Introduced.

WC_API_Orders::get_order_notes() code WC 7.7.0

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

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

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

	$args = array(
		'post_id' => $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[] = array(
			'id'            => $note->comment_ID,
			'created_at'    => $this->server->format_datetime( $note->comment_date_gmt ),
			'note'          => $note->comment_content,
			'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ),
		);
	}

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