• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql-woocommerce / 27386231983

12 Jun 2026 12:25AM UTC coverage: 91.791%. Remained the same
27386231983

Pull #1019

github

web-flow
Merge 46a421a18 into 01876f534
Pull Request #1019: fix: address WordPress.org plugin review (rename + prefixing + headers)

1327 of 1584 new or added lines in 200 files covered. (83.78%)

1 existing line in 1 file now uncovered.

18505 of 20160 relevant lines covered (91.79%)

151.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.18
/includes/mutation/class-order-note-delete.php
1
<?php
2
/**
3
 * Mutation - deleteOrderNote
4
 *
5
 * Registers mutation for delete an order note.
6
 *
7
 * @package WPGraphQL\WooCommerce\Mutation
8
 * @since 1.0.0
9
 */
10

11
namespace WPGraphQL\WooCommerce\Mutation;
12

13
use GraphQL\Error\UserError;
14
use GraphQL\Type\Definition\ResolveInfo;
15
use WPGraphQL\AppContext;
16
use WPGraphQL\Model\Comment;
17
use WPGraphQL\Utils\Utils;
18
use WPGraphQL\WooCommerce\Data\Mutation\Order_Mutation;
19
use WPGraphQL\WooCommerce\Model\Order;
20

21
/**
22
 * Class Order_Note_Delete
23
 */
24
class Order_Note_Delete {
25
        /**
26
         * Registers mutation
27
         *
28
         * @return void
29
         */
30
        public static function register_mutation() {
31
                register_graphql_mutation(
296✔
32
                        'deleteOrderNote',
296✔
33
                        [
296✔
34
                                'inputFields'         => self::get_input_fields(),
296✔
35
                                'outputFields'        => self::get_output_fields(),
296✔
36
                                'mutateAndGetPayload' => self::mutate_and_get_payload(),
296✔
37
                        ]
296✔
38
                );
296✔
39
        }
40

41
        /**
42
         * Defines the mutation input field configuration
43
         *
44
         * @return array
45
         */
46
        public static function get_input_fields() {
47
                return [
296✔
48
                        'id'      => [
296✔
49
                                'type'        => 'ID',
296✔
50
                                'description' => static function () {
296✔
51
                                        return __( 'Database ID or global ID of the order note', 'graphql-for-ecommerce' );
2✔
52
                                },
296✔
53
                        ],
296✔
54
                        'orderId' => [
296✔
55
                                'type'        => 'ID',
296✔
56
                                'description' => static function () {
296✔
57
                                        return __( 'Database ID or global ID of the order', 'graphql-for-ecommerce' );
2✔
58
                                },
296✔
59
                        ],
296✔
60
                        'force'   => [
296✔
61
                                'type'        => 'Boolean',
296✔
62
                                'description' => static function () {
296✔
63
                                        return __( 'Delete or simply place in trash.', 'graphql-for-ecommerce' );
2✔
64
                                },
296✔
65
                        ],
296✔
66
                ];
296✔
67
        }
68

69
        /**
70
         * Defines the mutation output field configuration
71
         *
72
         * @return array
73
         */
74
        public static function get_output_fields() {
75
                return [
296✔
76
                        'orderNote' => [
296✔
77
                                'type'    => 'OrderNote',
296✔
78
                                'resolve' => static function ( $payload ) {
296✔
79
                                        return new Comment( $payload['note'] );
1✔
80
                                },
296✔
81
                        ],
296✔
82
                        'order'     => [
296✔
83
                                'type'    => 'Order',
296✔
84
                                'resolve' => static function ( $payload ) {
296✔
85
                                        return new Order( $payload['order_id'] );
1✔
86
                                },
296✔
87
                        ],
296✔
88
                ];
296✔
89
        }
90

91
        /**
92
         * Defines the mutation data modification closure.
93
         *
94
         * @return callable
95
         */
96
        public static function mutate_and_get_payload() {
97
                return static function ( $input, AppContext $context, ResolveInfo $info ) {
296✔
98
                        // Retrieve order ID.
99
                        $order_id = Utils::get_database_id_from_id( $input['orderId'] );
1✔
100

101
                        if ( ! $order_id ) {
1✔
NEW
102
                                throw new UserError( __( 'Order ID provided is invalid. Please check input and try again.', 'graphql-for-ecommerce' ) );
×
103
                        }
104

105
                        // Check if authorized to delete this order note.
106
                        if ( ! Order_Mutation::authorized( $input, $context, $info, 'delete', $order_id ) ) {
1✔
107
                                throw new UserError( __( 'User does not have the capabilities necessary to delete an order.', 'graphql-for-ecommerce' ) );
1✔
108
                        }
109

110
                        if ( isset( $input['forceDelete'] ) && false === $input['forceDelete'] ) {
1✔
NEW
111
                                throw new UserError( __( 'woocommerce_rest_trash_not_supported', 'graphql-for-ecommerce' ) );
×
112
                        }
113

114
                        /**
115
                         * Get Order model instance for output.
116
                         *
117
                         * @var \WC_Order $order
118
                         */
119
                        $order = new Order( $order_id );
1✔
120

121
                        if ( ! $order ) {
1✔
NEW
122
                                throw new UserError( __( 'Invalid order ID.', 'graphql-for-ecommerce' ) );
×
123
                        }
124

125
                        $id = Utils::get_database_id_from_id( $input['id'] );
1✔
126
                        if ( ! $id ) {
1✔
NEW
127
                                throw new UserError( __( 'Order note ID provided is invalid. Please check input and try again.', 'graphql-for-ecommerce' ) );
×
128
                        }
129

130
                        $note = get_comment( $id );
1✔
131

132
                        if ( empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) {
1✔
NEW
133
                                throw new UserError( __( 'Invalid resource ID.', 'graphql-for-ecommerce' ) );
×
134
                        }
135

136
                        $comment_id = absint( $note->comment_ID );
1✔
137
                        $result     = wc_delete_order_note( $comment_id );
1✔
138

139
                        if ( ! $result ) {
1✔
NEW
140
                                throw new UserError( __( 'Unable to delete order note.', 'graphql-for-ecommerce' ) );
×
141
                        }
142

143
                        return [
1✔
144
                                'order_id' => $order_id,
1✔
145
                                'note'     => $note,
1✔
146
                        ];
1✔
147
                };
296✔
148
        }
149
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc