WC_REST_Order_Notes_V1_Controller::delete_item()
Delete a single order note.
Метод класса: WC_REST_Order_Notes_V1_Controller{}
Хуки из метода
Возвращает
WP_REST_Response|WP_Error
.
Использование
$WC_REST_Order_Notes_V1_Controller = new WC_REST_Order_Notes_V1_Controller(); $WC_REST_Order_Notes_V1_Controller->delete_item( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Код WC_REST_Order_Notes_V1_Controller::delete_item() WC REST Order Notes V1 Controller::delete item WC 9.3.3
public function delete_item( $request ) { $id = (int) $request['id']; $force = isset( $request['force'] ) ? (bool) $request['force'] : false; // We don't support trashing for this type, error out. if ( ! $force ) { return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); } $order = wc_get_order( (int) $request['order_id'] ); if ( ! $order || $this->post_type !== $order->get_type() ) { return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); } $note = get_comment( $id ); if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) { return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); } $request->set_param( 'context', 'edit' ); $response = $this->prepare_item_for_response( $note, $request ); $result = wc_delete_order_note( $note->comment_ID ); if ( ! $result ) { return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), 'order_note' ), array( 'status' => 500 ) ); } /** * Fires after a order note is deleted or trashed via the REST API. * * @param WP_Comment $note The deleted or trashed order note. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. */ do_action( 'woocommerce_rest_delete_order_note', $note, $response, $request ); return $response; }