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

wp-graphql / wp-graphql-woocommerce / 23675172456

28 Mar 2026 02:10AM UTC coverage: 70.983% (-18.4%) from 89.424%
23675172456

Pull #1003

github

web-flow
Merge 05339093d into 6fb7b226f
Pull Request #1003: devops: WC email template tests, COT cursor HPOS fix, checkout account auth

71 of 81 new or added lines in 5 files covered. (87.65%)

3346 existing lines in 124 files now uncovered.

12576 of 17717 relevant lines covered (70.98%)

55.38 hits per line

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

58.06
/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 TBD
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(
110✔
32
                        'deleteOrderNote',
110✔
33
                        [
110✔
34
                                'inputFields'         => self::get_input_fields(),
110✔
35
                                'outputFields'        => self::get_output_fields(),
110✔
36
                                'mutateAndGetPayload' => self::mutate_and_get_payload(),
110✔
37
                        ]
110✔
38
                );
110✔
39
        }
40

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

63
        /**
64
         * Defines the mutation output field configuration
65
         *
66
         * @return array
67
         */
68
        public static function get_output_fields() {
69
                return [
110✔
70
                        'orderNote' => [
110✔
71
                                'type'    => 'OrderNote',
110✔
72
                                'resolve' => static function ( $payload ) {
110✔
UNCOV
73
                                        return new Comment( $payload['note'] );
×
74
                                },
110✔
75
                        ],
110✔
76
                        'order'     => [
110✔
77
                                'type'    => 'Order',
110✔
78
                                'resolve' => static function ( $payload ) {
110✔
UNCOV
79
                                        return new Order( $payload['order_id'] );
×
80
                                },
110✔
81
                        ],
110✔
82
                ];
110✔
83
        }
84

85
        /**
86
         * Defines the mutation data modification closure.
87
         *
88
         * @return callable
89
         */
90
        public static function mutate_and_get_payload() {
91
                return static function ( $input, AppContext $context, ResolveInfo $info ) {
110✔
92
                        // Retrieve order ID.
UNCOV
93
                        $order_id = Utils::get_database_id_from_id( $input['orderId'] );
×
94

UNCOV
95
                        if ( ! $order_id ) {
×
96
                                throw new UserError( __( 'Order ID provided is invalid. Please check input and try again.', 'wp-graphql-woocommerce' ) );
×
97
                        }
98

99
                        // Check if authorized to delete this order note.
UNCOV
100
                        if ( ! Order_Mutation::authorized( $input, $context, $info, 'delete', $order_id ) ) {
×
UNCOV
101
                                throw new UserError( __( 'User does not have the capabilities necessary to delete an order.', 'wp-graphql-woocommerce' ) );
×
102
                        }
103

UNCOV
104
                        if ( isset( $input['forceDelete'] ) && false === $input['forceDelete'] ) {
×
105
                                throw new UserError( __( 'woocommerce_rest_trash_not_supported', 'wp-graphql-woocommerce' ) );
×
106
                        }
107

108
                        /**
109
                         * Get Order model instance for output.
110
                         *
111
                         * @var \WC_Order $order
112
                         */
UNCOV
113
                        $order = new Order( $order_id );
×
114

UNCOV
115
                        if ( ! $order ) {
×
116
                                throw new UserError( __( 'Invalid order ID.', 'wp-graphql-woocommerce' ) );
×
117
                        }
118

UNCOV
119
                        $id = Utils::get_database_id_from_id( $input['id'] );
×
UNCOV
120
                        if ( ! $id ) {
×
121
                                throw new UserError( __( 'Order note ID provided is invalid. Please check input and try again.', 'wp-graphql-woocommerce' ) );
×
122
                        }
123

UNCOV
124
                        $note = get_comment( $id );
×
125

UNCOV
126
                        if ( empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) {
×
127
                                throw new UserError( __( 'Invalid resource ID.', 'wp-graphql-woocommerce' ) );
×
128
                        }
129

UNCOV
130
                        $comment_id = absint( $note->comment_ID );
×
UNCOV
131
                        $result     = wc_delete_order_note( $comment_id );
×
132

UNCOV
133
                        if ( ! $result ) {
×
134
                                throw new UserError( __( 'Unable to delete order note.', 'wp-graphql-woocommerce' ) );
×
135
                        }
136

UNCOV
137
                        return [
×
UNCOV
138
                                'order_id' => $order_id,
×
UNCOV
139
                                'note'     => $note,
×
UNCOV
140
                        ];
×
141
                };
110✔
142
        }
143
}
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