• 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

60.0
/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 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_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(
110✔
32
                        'createOrderNote',
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
                        'orderId'        => [
110✔
49
                                'type'        => 'ID',
110✔
50
                                'description' => __( 'Database ID or global ID of the order', 'wp-graphql-woocommerce' ),
110✔
51
                        ],
110✔
52
                        'note'           => [
110✔
53
                                'type'        => 'String',
110✔
54
                                'description' => __( 'Order note.', 'wp-graphql-woocommerce' ),
110✔
55
                        ],
110✔
56
                        'isCustomerNote' => [
110✔
57
                                'type'        => 'Boolean',
110✔
58
                                'description' => __( 'Shows/define if the note is only for reference or for the customer (the user will be notified).', '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 create order notes.
UNCOV
100
                        if ( ! Order_Mutation::authorized( $input, $context, $info, 'create', $order_id ) ) {
×
UNCOV
101
                                throw new UserError( __( 'User does not have the capabilities necessary to create an order note.', 'wp-graphql-woocommerce' ) );
×
102
                        }
103

104
                        /**
105
                         * Get Order model instance for output.
106
                         *
107
                         * @var \WC_Order $order
108
                         */
UNCOV
109
                        $order = new Order( $order_id );
×
110

UNCOV
111
                        if ( ! $order ) {
×
112
                                throw new UserError( __( 'Invalid order ID.', 'wp-graphql-woocommerce' ) );
×
113
                        }
114

UNCOV
115
                        $note_content = ! empty( $input['note'] ) ? $input['note'] : '';
×
UNCOV
116
                        if ( empty( $note_content ) ) {
×
UNCOV
117
                                throw new UserError( __( 'Order note content is required.', 'wp-graphql-woocommerce' ) );
×
118
                        }
119

UNCOV
120
                        $is_customer_note = ! empty( $input['isCustomerNote'] ) ? $input['isCustomerNote'] : false;
×
121

122
                        // Create the order note.
UNCOV
123
                        $note_id = $order->add_order_note( $note_content, $is_customer_note );
×
124

UNCOV
125
                        if ( ! $note_id ) {
×
126
                                throw new UserError( __( 'Unable to create order note.', 'wp-graphql-woocommerce' ) );
×
127
                        }
128

129
                        // Get the created note.
UNCOV
130
                        $note = get_comment( $note_id );
×
131

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

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