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

wp-graphql / wp-graphql-woocommerce / 27452430870

13 Jun 2026 01:26AM UTC coverage: 91.8%. Remained the same
27452430870

Pull #1019

github

web-flow
Merge f03617ca3 into 2ce9424e1
Pull Request #1019: fix: address WordPress.org plugin review (rename + prefixing + headers)

1330 of 1587 new or added lines in 201 files covered. (83.81%)

1 existing line in 1 file now uncovered.

18528 of 20183 relevant lines covered (91.8%)

152.68 hits per line

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

93.94
/includes/mutation/class-order-note-create.php
1
<?php
2
/**
3
 * Mutation - createOrderNote
4
 *
5
 * Registers mutation for create 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_Create
23
 */
24
class Order_Note_Create {
25
        /**
26
         * Registers mutation
27
         *
28
         * @return void
29
         */
30
        public static function register_mutation() {
31
                register_graphql_mutation(
298✔
32
                        'createOrderNote',
298✔
33
                        [
298✔
34
                                'inputFields'         => self::get_input_fields(),
298✔
35
                                'outputFields'        => self::get_output_fields(),
298✔
36
                                'mutateAndGetPayload' => self::mutate_and_get_payload(),
298✔
37
                        ]
298✔
38
                );
298✔
39
        }
40

41
        /**
42
         * Defines the mutation input field configuration
43
         *
44
         * @return array
45
         */
46
        public static function get_input_fields() {
47
                return [
298✔
48
                        'orderId'        => [
298✔
49
                                'type'        => 'ID',
298✔
50
                                'description' => static function () {
298✔
51
                                        return __( 'Database ID or global ID of the order', 'graphql-for-ecommerce' );
2✔
52
                                },
298✔
53
                        ],
298✔
54
                        'note'           => [
298✔
55
                                'type'        => 'String',
298✔
56
                                'description' => static function () {
298✔
57
                                        return __( 'Order note.', 'graphql-for-ecommerce' );
2✔
58
                                },
298✔
59
                        ],
298✔
60
                        'isCustomerNote' => [
298✔
61
                                'type'        => 'Boolean',
298✔
62
                                'description' => static function () {
298✔
63
                                        return __( 'Shows/define if the note is only for reference or for the customer (the user will be notified).', 'graphql-for-ecommerce' );
2✔
64
                                },
298✔
65
                        ],
298✔
66
                ];
298✔
67
        }
68

69
        /**
70
         * Defines the mutation output field configuration
71
         *
72
         * @return array
73
         */
74
        public static function get_output_fields() {
75
                return [
298✔
76
                        'orderNote' => [
298✔
77
                                'type'    => 'OrderNote',
298✔
78
                                'resolve' => static function ( $payload ) {
298✔
79
                                        return new Comment( $payload['note'] );
2✔
80
                                },
298✔
81
                        ],
298✔
82
                        'order'     => [
298✔
83
                                'type'    => 'Order',
298✔
84
                                'resolve' => static function ( $payload ) {
298✔
85
                                        return new Order( $payload['order_id'] );
2✔
86
                                },
298✔
87
                        ],
298✔
88
                ];
298✔
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 ) {
298✔
98
                        // Retrieve order ID.
99
                        $order_id = Utils::get_database_id_from_id( $input['orderId'] );
3✔
100

101
                        if ( ! $order_id ) {
3✔
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 create order notes.
106
                        if ( ! Order_Mutation::authorized( $input, $context, $info, 'create', $order_id ) ) {
3✔
107
                                throw new UserError( __( 'User does not have the capabilities necessary to create an order note.', 'graphql-for-ecommerce' ) );
1✔
108
                        }
109

110
                        /**
111
                         * Get Order model instance for output.
112
                         *
113
                         * @var \WC_Order $order
114
                         */
115
                        $order = new Order( $order_id );
3✔
116

117
                        if ( ! $order ) {
3✔
NEW
118
                                throw new UserError( __( 'Invalid order ID.', 'graphql-for-ecommerce' ) );
×
119
                        }
120

121
                        $note_content = ! empty( $input['note'] ) ? $input['note'] : '';
3✔
122
                        if ( empty( $note_content ) ) {
3✔
123
                                throw new UserError( __( 'Order note content is required.', 'graphql-for-ecommerce' ) );
1✔
124
                        }
125

126
                        $is_customer_note = ! empty( $input['isCustomerNote'] ) ? $input['isCustomerNote'] : false;
2✔
127

128
                        // Create the order note.
129
                        $note_id = $order->add_order_note( $note_content, $is_customer_note );
2✔
130

131
                        if ( ! $note_id ) {
2✔
NEW
132
                                throw new UserError( __( 'Unable to create order note.', 'graphql-for-ecommerce' ) );
×
133
                        }
134

135
                        // Get the created note.
136
                        $note = get_comment( $note_id );
2✔
137

138
                        if ( ! $note ) {
2✔
NEW
139
                                throw new UserError( __( 'Unable to retrieve created order note.', 'graphql-for-ecommerce' ) );
×
140
                        }
141

142
                        return [
2✔
143
                                'order_id' => $order_id,
2✔
144
                                'note'     => $note,
2✔
145
                        ];
2✔
146
                };
298✔
147
        }
148
}
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