@@ 242-260 (lines=19) @@ | ||
239 | * @param WP_REST_Request $request Full details about the request. |
|
240 | * @return WP_Error|WP_REST_Response |
|
241 | */ |
|
242 | public function get_item( $request ) { |
|
243 | $id = (int) $request['id']; |
|
244 | $order = get_post( (int) $request['order_id'] ); |
|
245 | ||
246 | if ( empty( $order->post_type ) || $this->post_type !== $order->post_type ) { |
|
247 | return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order id.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
248 | } |
|
249 | ||
250 | $note = get_comment( $id ); |
|
251 | ||
252 | if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->ID ) ) { |
|
253 | return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
254 | } |
|
255 | ||
256 | $order_note = $this->prepare_item_for_response( $note, $request ); |
|
257 | $response = rest_ensure_response( $order_note ); |
|
258 | ||
259 | return $response; |
|
260 | } |
|
261 | ||
262 | /** |
|
263 | * Delete a single order note. |
@@ 126-144 (lines=19) @@ | ||
123 | * @param WP_REST_Request $request Full details about the request. |
|
124 | * @return WP_Error|WP_REST_Response |
|
125 | */ |
|
126 | public function get_item( $request ) { |
|
127 | $id = (int) $request['id']; |
|
128 | $product = get_post( (int) $request['product_id'] ); |
|
129 | ||
130 | if ( empty( $product->post_type ) || 'product' !== $product->post_type ) { |
|
131 | return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product id.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
132 | } |
|
133 | ||
134 | $review = get_comment( $id ); |
|
135 | ||
136 | if ( empty( $id ) || empty( $review ) || intval( $review->comment_post_ID ) !== intval( $product->ID ) ) { |
|
137 | return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
138 | } |
|
139 | ||
140 | $delivery = $this->prepare_item_for_response( $review, $request ); |
|
141 | $response = rest_ensure_response( $delivery ); |
|
142 | ||
143 | return $response; |
|
144 | } |
|
145 | ||
146 | /** |
|
147 | * Prepare a single product review output for response. |