WC_API_Orders::delete_order_note()
Delete order note
Method of the class: WC_API_Orders{}
Hooks from the method
Return
WP_Error|Array
. error or deleted message
Usage
$WC_API_Orders = new WC_API_Orders(); $WC_API_Orders->delete_order_note( $order_id, $id );
- $order_id(string) (required)
- order ID
- $id(string) (required)
- note ID
Changelog
Since 2.2 | Introduced. |
WC_API_Orders::delete_order_note() WC API Orders::delete order note code WC 7.7.0
public function delete_order_note( $order_id, $id ) { try { $order_id = $this->validate_request( $order_id, $this->post_type, 'delete' ); if ( is_wp_error( $order_id ) ) { return $order_id; } // Validate note ID $id = absint( $id ); if ( empty( $id ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'Invalid order note ID', 'woocommerce' ), 400 ); } // Ensure note ID is valid $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 ); } // Ensure note ID is associated with given order if ( $note->comment_post_ID != $order_id ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'The order note ID provided is not associated with the order', 'woocommerce' ), 400 ); } // Force delete since trashed order notes could not be managed through comments list table $result = wc_delete_order_note( $note->comment_ID ); if ( ! $result ) { throw new WC_API_Exception( 'woocommerce_api_cannot_delete_order_note', __( 'This order note cannot be deleted', 'woocommerce' ), 500 ); } do_action( 'woocommerce_api_delete_order_note', $note->comment_ID, $order_id, $this ); return array( 'message' => __( 'Permanently deleted order note', 'woocommerce' ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } }