| @@ 236-254 (lines=19) @@ | ||
| 233 | * @param WP_REST_Request $request Full details about the request. |
|
| 234 | * @return WP_Error|WP_REST_Response |
|
| 235 | */ |
|
| 236 | public function get_item( $request ) { |
|
| 237 | $id = (int) $request['id']; |
|
| 238 | $order = get_post( (int) $request['order_id'] ); |
|
| 239 | ||
| 240 | if ( empty( $order->post_type ) || 'shop_order' !== $order->post_type ) { |
|
| 241 | return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order id.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 242 | } |
|
| 243 | ||
| 244 | $note = get_comment( $id ); |
|
| 245 | ||
| 246 | if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->ID ) ) { |
|
| 247 | return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
| 248 | } |
|
| 249 | ||
| 250 | $order_note = $this->prepare_item_for_response( $note, $request ); |
|
| 251 | $response = rest_ensure_response( $order_note ); |
|
| 252 | ||
| 253 | return $response; |
|
| 254 | } |
|
| 255 | ||
| 256 | /** |
|
| 257 | * 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. |
|