WC_API_Orders::get_order_note() public WC 2.2
Get an order note for the given order ID and ID
{} Это метод класса: WC_API_Orders{}
Хуки из метода
Возвращает
Массив/WP_Error.
Использование
$WC_API_Orders = new WC_API_Orders(); $WC_API_Orders->get_order_note( $order_id, $id, $fields );
- $order_id(строка) (обязательный)
- order ID
- $id(строка) (обязательный)
- order note ID
- $fields(строка/null)
- fields to limit response to
Список изменений
С версии 2.2 | Введена. |
Код WC_API_Orders::get_order_note() WC API Orders::get order note WC 5.0.0
public function get_order_note( $order_id, $id, $fields = null ) {
try {
// Validate order ID
$order_id = $this->validate_request( $order_id, $this->post_type, 'read' );
if ( is_wp_error( $order_id ) ) {
return $order_id;
}
$id = absint( $id );
if ( empty( $id ) ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'Invalid order note ID', 'woocommerce' ), 400 );
}
$note = get_comment( $id );
if ( is_null( $note ) ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'An order note with the provided ID could not be found', 'woocommerce' ), 404 );
}
$order_note = 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_note' => apply_filters( 'woocommerce_api_order_note_response', $order_note, $id, $fields, $note, $order_id, $this ) );
} catch ( WC_API_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
}