WC_REST_Order_Notes_V2_Controller::get_items()
Get order notes from an order.
Метод класса: WC_REST_Order_Notes_V2_Controller{}
Хуков нет.
Возвращает
Массив|WP_Error
.
Использование
$WC_REST_Order_Notes_V2_Controller = new WC_REST_Order_Notes_V2_Controller(); $WC_REST_Order_Notes_V2_Controller->get_items( $request );
- $request(WP_REST_Request) (обязательный)
- Request data.
Код WC_REST_Order_Notes_V2_Controller::get_items() WC REST Order Notes V2 Controller::get items WC 9.3.3
public function get_items( $request ) { $order = wc_get_order( (int) $request['order_id'] ); if ( ! $order || $this->post_type !== $order->get_type() ) { return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); } $args = array( 'post_id' => $order->get_id(), 'approve' => 'approve', 'type' => 'order_note', ); // Allow filter by order note type. if ( 'customer' === $request['type'] ) { $args['meta_query'] = array( // WPCS: slow query ok. array( 'key' => 'is_customer_note', 'value' => 1, 'compare' => '=', ), ); } elseif ( 'internal' === $request['type'] ) { $args['meta_query'] = array( // WPCS: slow query ok. array( 'key' => 'is_customer_note', 'compare' => 'NOT EXISTS', ), ); } 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 ); $data = array(); foreach ( $notes as $note ) { $order_note = $this->prepare_item_for_response( $note, $request ); $order_note = $this->prepare_response_for_collection( $order_note ); $data[] = $order_note; } return rest_ensure_response( $data ); }