Automattic\WooCommerce\Admin\API

Notes::batch_update_items()publicWC 1.0

Batch update a set of notes.

Method of the class: Notes{}

No Hooks.

Return

WP_REST_Request|WP_Error.

Usage

$Notes = new Notes();
$Notes->batch_update_items( $request );
$request(WP_REST_Request) (required)
Request object.

Notes::batch_update_items() code WC 8.6.1

public function batch_update_items( $request ) {
	$data     = array();
	$note_ids = $request->get_param( 'noteIds' );

	if ( ! isset( $note_ids ) || ! is_array( $note_ids ) ) {
		return new \WP_Error(
			'woocommerce_note_invalid_ids',
			__( 'Please provide an array of IDs through the noteIds param.', 'woocommerce' ),
			array( 'status' => 422 )
		);
	}

	foreach ( (array) $note_ids as $note_id ) {
		$note = NotesRepository::get_note( (int) $note_id );
		if ( $note ) {
			NotesRepository::update_note( $note, $this->get_requested_updates( $request ) );
			$data[] = $this->prepare_note_data_for_response( $note, $request );
		}
	}

	$response = rest_ensure_response( $data );
	$response->header( 'X-WP-Total', NotesRepository::get_notes_count( array( 'info', 'warning' ), array() ) );
	return $response;
}