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

wp-graphql / wp-graphql-woocommerce / 11577662414

29 Oct 2024 03:54PM UTC coverage: 84.451% (-0.06%) from 84.506%
11577662414

push

github

web-flow
fix: General improvements and bugfixes (#899)

61 of 72 new or added lines in 4 files covered. (84.72%)

7 existing lines in 1 file now uncovered.

12514 of 14818 relevant lines covered (84.45%)

72.37 hits per line

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

87.26
/includes/data/mutation/class-order-mutation.php
1
<?php
2
/**
3
 * Defines helper functions for executing mutations related to the orders.
4
 *
5
 * @package WPGraphQL\WooCommerce\Data\Mutation
6
 * @since 0.2.0
7
 */
8

9
namespace WPGraphQL\WooCommerce\Data\Mutation;
10

11
use GraphQL\Error\UserError;
12

13

14
/**
15
 * Class - Order_Mutation
16
 */
17
class Order_Mutation {
18
        /**
19
         * Filterable authentication function.
20
         *
21
         * @param array                                $input     Input data describing order.
22
         * @param \WPGraphQL\AppContext                $context   AppContext instance.
23
         * @param \GraphQL\Type\Definition\ResolveInfo $info      ResolveInfo instance.
24
         * @param string                               $mutation  Mutation being executed.
25
         * @param integer|null                         $order_id  Order ID.
26
         *
27
         * @return boolean
28
         */
29
        public static function authorized( $input, $context, $info, $mutation = 'create', $order_id = null ) {
30
                /**
31
                 * Get order post type.
32
                 *
33
                 * @var \WP_Post_Type $post_type_object
34
                 */
35
                $post_type_object = get_post_type_object( 'shop_order' );
4✔
36

37
                return apply_filters(
4✔
38
                        "graphql_woocommerce_authorized_to_{$mutation}_orders",
4✔
39
                        current_user_can(
4✔
40
                                'delete' === $mutation
4✔
41
                                        ? $post_type_object->cap->delete_posts
1✔
42
                                        : $post_type_object->cap->edit_posts
4✔
43
                        ),
4✔
44
                        $order_id,
4✔
45
                        $input,
4✔
46
                        $context,
4✔
47
                        $info
4✔
48
                );
4✔
49
        }
50

51
        /**
52
         * Create an order.
53
         *
54
         * @param array                                $input    Input data describing order.
55
         * @param \WPGraphQL\AppContext                $context  AppContext instance.
56
         * @param \GraphQL\Type\Definition\ResolveInfo $info     ResolveInfo instance.
57
         *
58
         * @return integer
59
         *
60
         * @throws \GraphQL\Error\UserError  Error creating order.
61
         */
62
        public static function create_order( $input, $context, $info ) {
63
                $order = new \WC_Order();
4✔
64

65
                $order->set_currency( ! empty( $input['currency'] ) ? $input['currency'] : get_woocommerce_currency() );
4✔
66
                $order->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
4✔
67
                $order->set_customer_ip_address( \WC_Geolocation::get_ip_address() );
4✔
68
                $order->set_customer_user_agent( wc_get_user_agent() );
4✔
69

70
                $order_id = $order->save();
4✔
71

72
                $order_keys = [
4✔
73
                        'status'       => 'status',
4✔
74
                        'customerId'   => 'customer_id',
4✔
75
                        'customerNote' => 'customer_note',
4✔
76
                        'parent'       => 'parent',
4✔
77
                        'createdVia'   => 'created_via',
4✔
78
                ];
4✔
79

80
                $args = [ 'order_id' => $order_id ];
4✔
81
                foreach ( $input as $key => $value ) {
4✔
82
                        if ( array_key_exists( $key, $order_keys ) ) {
4✔
83
                                $args[ $order_keys[ $key ] ] = $value;
4✔
84
                        }
85
                }
86

87
                /**
88
                 * Action called before order is created.
89
                 *
90
                 * @param array                                $input   Input data describing order.
91
                 * @param \WPGraphQL\AppContext                $context Request AppContext instance.
92
                 * @param \GraphQL\Type\Definition\ResolveInfo $info    Request ResolveInfo instance.
93
                 */
94
                do_action( 'graphql_woocommerce_before_order_create', $input, $context, $info );
4✔
95

96
                $order = \wc_create_order( $args );
4✔
97
                if ( is_wp_error( $order ) ) {
4✔
98
                        throw new UserError( $order->get_error_code() . $order->get_error_message() );
×
99
                }
100

101
                /**
102
                 * Action called after order is created.
103
                 *
104
                 * @param \WC_Order    $order   WC_Order instance.
105
                 * @param array       $input   Input data describing order.
106
                 * @param \WPGraphQL\AppContext  $context Request AppContext instance.
107
                 * @param \GraphQL\Type\Definition\ResolveInfo $info    Request ResolveInfo instance.
108
                 */
109
                do_action( 'graphql_woocommerce_after_order_create', $order, $input, $context, $info );
4✔
110

111
                return $order->get_id();
4✔
112
        }
113

114
        /**
115
         * Add items to order.
116
         *
117
         * @param array                                $input     Input data describing order.
118
         * @param int                                  $order_id  Order object.
119
         * @param \WPGraphQL\AppContext                $context   AppContext instance.
120
         * @param \GraphQL\Type\Definition\ResolveInfo $info      ResolveInfo instance.
121
         *
122
         * @throws \Exception  Failed to retrieve order.
123
         *
124
         * @return void
125
         */
126
        public static function add_items( $input, $order_id, $context, $info ) {
127
                /** @var \WC_Order|false $order */
128
                $order = \WC_Order_Factory::get_order( $order_id );
4✔
129
                if ( false === $order ) {
4✔
NEW
130
                        throw new \Exception( __( 'Failed to retrieve order.', 'wp-graphql-woocommerce' ) );
×
131
                }
132

133
                $item_group_keys = [
4✔
134
                        'lineItems'     => 'line_item',
4✔
135
                        'shippingLines' => 'shipping',
4✔
136
                        'feeLines'      => 'fee',
4✔
137
                ];
4✔
138

139
                $order_items = [];
4✔
140
                foreach ( $input as $key => $group_items ) {
4✔
141
                        if ( array_key_exists( $key, $item_group_keys ) ) {
4✔
142
                                $type                 = $item_group_keys[ $key ];
4✔
143
                                $order_items[ $type ] = [];
4✔
144

145
                                /**
146
                                 * Action called before an item group is added to an order.
147
                                 *
148
                                 * @param array                                $group_items  Items data being added.
149
                                 * @param \WC_Order                            $order        Order object.
150
                                 * @param \WPGraphQL\AppContext                $context      Request AppContext instance.
151
                                 * @param \GraphQL\Type\Definition\ResolveInfo $info         Request ResolveInfo instance.
152
                                 */
153
                                do_action( "graphql_woocommerce_before_{$type}s_added_to_order", $group_items, $order, $context, $info );
4✔
154

155
                                foreach ( $group_items as $item_data ) {
4✔
156
                                        $item = self::set_item(
4✔
157
                                                $item_data,
4✔
158
                                                $type,
4✔
159
                                                $order,
4✔
160
                                                $context,
4✔
161
                                                $info
4✔
162
                                        );
4✔
163

164
                                        /**
165
                                         * Action called before an item group is added to an order.
166
                                         *
167
                                         * @param \WC_Order_Item                       $item      Order item object.
168
                                         * @param array                                $item_data Item data being added.
169
                                         * @param \WC_Order                            $order     Order object.
170
                                         * @param \WPGraphQL\AppContext                $context   Request AppContext instance.
171
                                         * @param \GraphQL\Type\Definition\ResolveInfo $info      Request ResolveInfo instance.
172
                                         */
173
                                        do_action( "graphql_woocommerce_before_{$type}_added_to_order", $item, $item_data, $order, $context, $info );
4✔
174

175
                                        if ( 0 === $item->get_id() ) {
4✔
176
                                                $order->add_item( $item );
4✔
177
                                                $order_items[ $type ][] = $item;
4✔
178
                                        } else {
179
                                                $item->save();
1✔
180
                                                $order_items[ $type ][] = $item;
1✔
181
                                        }
182
                                }
183

184
                                /**
185
                                 * Action called after an item group is added to an order, and before the order has been saved with the new items.
186
                                 *
187
                                 * @param array                                $group_items  Item data being added.
188
                                 * @param \WC_Order                            $order        Order object.
189
                                 * @param \WPGraphQL\AppContext                $context      Request AppContext instance.
190
                                 * @param \GraphQL\Type\Definition\ResolveInfo $info         Request ResolveInfo instance.
191
                                 */
192
                                do_action( "graphql_woocommerce_after_{$type}s_added_to_order", $group_items, $order, $context, $info );
4✔
193
                        }//end if
194
                }//end foreach
195

196
                /**
197
                 * Action called after all items have been added and right before the new items have been saved.
198
                 *
199
                 * @param array<string, array<\WC_Order_Item>> $order_items Order items.
200
                 * @param \WC_Order                            $order       WC_Order instance.
201
                 * @param array                                $input       Input data describing order.
202
                 * @param \WPGraphQL\AppContext                $context     Request AppContext instance.
203
                 * @param \GraphQL\Type\Definition\ResolveInfo $info        Request ResolveInfo instance.
204
                 */
205
                do_action( 'graphql_woocommerce_before_new_order_items_save', $order_items, $order, $input, $context, $info );
4✔
206

207
                $order->save();
4✔
208
        }
209

210
        /**
211
         *
212
         * @param array<string, mixed>                 $item_data  Item data.
213
         * @param string                               $type       Item type.
214
         * @param \WC_Order                            $order      Order object.
215
         * @param \WPGraphQL\AppContext                $context    AppContext instance.
216
         * @param \GraphQL\Type\Definition\ResolveInfo $info       ResolveInfo instance.
217
         *
218
         * @return \WC_Order_Item
219
         */
220
        public static function set_item( $item_data, $type, $order, $context, $info ) {
221
                $item_id    = ! empty( $item_data['id'] ) ? $item_data['id'] : 0;
4✔
222
                $item_class = self::get_order_item_classname( $type, $item_id );
4✔
223

224
                /** @var \WC_Order_Item $item */
225
                $item = new $item_class( $item_id );
4✔
226

227
                /**
228
                 * Filter the order item object before it is created.
229
                 *
230
                 * @param \WC_Order_Item                       $item       Order item object.
231
                 * @param array                                $item_data  Item data.
232
                 * @param \WC_Order                            $order      Order object.
233
                 * @param \WPGraphQL\AppContext                $context    AppContext instance.
234
                 * @param \GraphQL\Type\Definition\ResolveInfo $info       ResolveInfo instance.
235
                 */
236
                $item = apply_filters( "graphql_create_order_{$type}_object", $item, $item_data, $order, $context, $info );
4✔
237

238
                self::map_input_to_item( $item, $item_data, $type );
4✔
239

240
                /**
241
                 * Action called after an order item is created.
242
                 *
243
                 * @param \WC_Order_Item                       $item       Order item object.
244
                 * @param array                                $item_data  Item data.
245
                 * @param \WC_Order                            $order      Order object.
246
                 * @param \WPGraphQL\AppContext                $context    AppContext instance.
247
                 * @param \GraphQL\Type\Definition\ResolveInfo $info       ResolveInfo instance.
248
                 */
249
                do_action( "graphql_create_order_{$type}", $item, $item_data, $order, $context, $info );
4✔
250

251
                return $item;
4✔
252
        }
253

254
        /**
255
         * Get order item class name.
256
         *
257
         * @param string $type Order item type.
258
         * @param int    $id  Order item ID.
259
         *
260
         * @return string
261
         */
262
        public static function get_order_item_classname( $type, $id = 0 ) {
263
                $classname = false;
4✔
264
                switch ( $type ) {
265
                        case 'line_item':
4✔
266
                        case 'product':
4✔
267
                                $classname = 'WC_Order_Item_Product';
4✔
268
                                break;
4✔
269
                        case 'coupon':
4✔
NEW
270
                                $classname = 'WC_Order_Item_Coupon';
×
NEW
271
                                break;
×
272
                        case 'fee':
4✔
273
                                $classname = 'WC_Order_Item_Fee';
4✔
274
                                break;
4✔
275
                        case 'shipping':
4✔
276
                                $classname = 'WC_Order_Item_Shipping';
4✔
277
                                break;
4✔
NEW
278
                        case 'tax':
×
NEW
279
                                $classname = 'WC_Order_Item_Tax';
×
NEW
280
                                break;
×
281
                }
282

283
                $classname = apply_filters( 'woocommerce_get_order_item_classname', $classname, $type, $id ); // phpcs:ignore WordPress.NamingConventions
4✔
284

285
                return $classname;
4✔
286
        }
287

288
        /**
289
         * Return array of item mapped with the provided $item_keys and extracts $meta_data
290
         *
291
         * @param \WC_Order_Item &$item      Order item.
292
         * @param array          $input      Item input data.
293
         * @param string         $type       Item type.
294
         *
295
         * @throws \Exception Failed to retrieve connected product.
296
         *
297
         * @return void
298
         */
299
        protected static function map_input_to_item( &$item, $input, $type ) {
300
                $item_keys = self::get_order_item_keys( $type );
4✔
301

302
                $args      = [];
4✔
303
                $meta_data = null;
4✔
304
                foreach ( $input as $key => $value ) {
4✔
305
                        if ( array_key_exists( $key, $item_keys ) ) {
4✔
306
                                $args[ $item_keys[ $key ] ] = $value;
4✔
307
                        } elseif ( 'metaData' === $key ) {
4✔
308
                                $meta_data = $value;
4✔
309
                        } else {
310
                                $args[ $key ] = $value;
4✔
311
                        }
312
                }
313

314
                // Calculate to subtotal/total for line items.
315
                if ( isset( $args['quantity'] ) ) {
4✔
316
                        $product = ( ! empty( $item['product_id'] ) )
4✔
317
                                ? wc_get_product( $item['product_id'] )
1✔
318
                                : wc_get_product( self::get_product_id( $args ) );
4✔
319
                        if ( ! is_object( $product ) ) {
4✔
320
                                throw new \Exception( __( 'Failed to retrieve product connected to order item.', 'wp-graphql-woocommerce' ) );
×
321
                        }
322

323
                        $total            = wc_get_price_excluding_tax( $product, [ 'qty' => $args['quantity'] ] );
4✔
324
                        $args['subtotal'] = ! empty( $args['subtotal'] ) ? $args['subtotal'] : $total;
4✔
325
                        $args['total']    = ! empty( $args['total'] ) ? $args['total'] : $total;
4✔
326
                }
327

328
                // Set item props.
329
                foreach ( $args as $key => $value ) {
4✔
330
                        if ( is_callable( [ $item, "set_{$key}" ] ) ) {
4✔
331
                                $item->{"set_{$key}"}( $value );
4✔
332
                        }
333
                }
334

335
                // Update item meta data if any is found.
336
                if ( empty( $meta_data ) ) {
4✔
337
                        return;
4✔
338
                }
339

340
                foreach ( $meta_data as $entry ) {
4✔
341
                        $exists = $item->get_meta( $entry['key'], true, 'edit' );
4✔
342
                        if ( '' !== $exists && $exists !== $entry['value'] ) {
4✔
343
                                $item->update_meta_data( $entry['key'], $entry['value'] );
1✔
344
                        } else {
345
                                $item->add_meta_data( $entry['key'], $entry['value'] );
4✔
346
                        }
347
                }
348
        }
349

350
        /**
351
         * Returns array of item keys by item type.
352
         *
353
         * @param string $type  Order item type.
354
         *
355
         * @return array
356
         */
357
        protected static function get_order_item_keys( $type ) {
358
                switch ( $type ) {
359
                        case 'line_item':
4✔
360
                                return [
4✔
361
                                        'productId'   => 'product_id',
4✔
362
                                        'variationId' => 'variation_id',
4✔
363
                                        'taxClass'    => 'tax_class',
4✔
364
                                ];
4✔
365

366
                        case 'shipping':
4✔
367
                                return [
4✔
368
                                        'name'        => 'order_item_name',
4✔
369
                                        'methodTitle' => 'method_title',
4✔
370
                                        'methodId'    => 'method_id',
4✔
371
                                        'instanceId'  => 'instance_id',
4✔
372
                                ];
4✔
373

374
                        case 'fee':
4✔
375
                                return [
4✔
376
                                        'name'      => 'name',
4✔
377
                                        'taxClass'  => 'tax_class',
4✔
378
                                        'taxStatus' => 'tax_status',
4✔
379
                                ];
4✔
380
                        default:
381
                                /**
382
                                 * Allow filtering of order item keys for unknown item types.
383
                                 *
384
                                 * @param array  $item_keys  Order item keys.
385
                                 * @param string $type       Order item type slug.
386
                                 */
387
                                return apply_filters( 'woographql_get_order_item_keys', [], $type );
×
388
                }//end switch
389
        }
390

391
        /**
392
         * Gets the product ID from the SKU or line item data ID.
393
         *
394
         * @param array $data  Line item data.
395
         *
396
         * @return integer
397
         * @throws \GraphQL\Error\UserError When SKU or ID is not valid.
398
         */
399
        protected static function get_product_id( $data ) {
400
                if ( ! empty( $data['sku'] ) ) {
4✔
401
                        $product_id = (int) wc_get_product_id_by_sku( $data['sku'] );
×
402
                } elseif ( ! empty( $data['variation_id'] ) ) {
4✔
403
                        $product_id = (int) $data['variation_id'];
4✔
404
                } elseif ( ! empty( $data['product_id'] ) ) {
4✔
405
                        $product_id = (int) $data['product_id'];
4✔
406
                } else {
407
                        throw new UserError( __( 'Product ID or SKU is required.', 'wp-graphql-woocommerce' ) );
×
408
                }
409

410
                return $product_id;
4✔
411
        }
412

413
        /**
414
         * Create/Update order item meta data.
415
         *
416
         * @param int                                  $item_id    Order item ID.
417
         * @param array                                $meta_data  Array of meta data.
418
         * @param \WPGraphQL\AppContext                $context    AppContext instance.
419
         * @param \GraphQL\Type\Definition\ResolveInfo $info       ResolveInfo instance.
420
         *
421
         * @throws \GraphQL\Error\UserError|\Exception  Invalid item input | Failed to retrieve order item.
422
         *
423
         * @return void
424
         */
425
        protected static function update_item_meta_data( $item_id, $meta_data, $context, $info ) {
UNCOV
426
                $item = \WC_Order_Factory::get_order_item( $item_id );
×
UNCOV
427
                if ( ! is_object( $item ) ) {
×
428
                        throw new \Exception( __( 'Failed to retrieve order item.', 'wp-graphql-woocommerce' ) );
×
429
                }
430

UNCOV
431
                foreach ( $meta_data as $entry ) {
×
UNCOV
432
                        $exists = $item->get_meta( $entry['key'], true, 'edit' );
×
UNCOV
433
                        if ( '' !== $exists && $exists !== $entry['value'] ) {
×
UNCOV
434
                                \wc_update_order_item_meta( $item_id, $entry['key'], $entry['value'] );
×
435
                        } else {
UNCOV
436
                                \wc_add_order_item_meta( $item_id, $entry['key'], $entry['value'] );
×
437
                        }
438
                }
439
        }
440

441
        /**
442
         * Add meta data not set in self::create_order().
443
         *
444
         * @param int                                  $order_id  Order ID.
445
         * @param array                                $input     Order properties.
446
         * @param \WPGraphQL\AppContext                $context   AppContext instance.
447
         * @param \GraphQL\Type\Definition\ResolveInfo $info      ResolveInfo instance.
448
         *
449
         * @throws \Exception  Failed to retrieve order.
450
         *
451
         * @return void
452
         */
453
        public static function add_order_meta( $order_id, $input, $context, $info ) {
454
                $order = \WC_Order_Factory::get_order( $order_id );
4✔
455
                if ( ! is_object( $order ) ) {
4✔
456
                        throw new \Exception( __( 'Failed to retrieve order.', 'wp-graphql-woocommerce' ) );
×
457
                }
458

459
                foreach ( $input as $key => $value ) {
4✔
460
                        switch ( $key ) {
461
                                case 'coupons':
4✔
462
                                case 'lineItems':
4✔
463
                                case 'shippingLines':
4✔
464
                                case 'feeLines':
4✔
465
                                case 'status':
4✔
466
                                        break;
4✔
467
                                case 'billing':
4✔
468
                                case 'shipping':
4✔
469
                                        self::update_address( $value, $order_id, $key );
4✔
470
                                        $order->apply_changes();
4✔
471
                                        break;
4✔
472
                                case 'metaData':
4✔
473
                                        if ( is_array( $value ) ) {
4✔
474
                                                foreach ( $value as $meta ) {
4✔
475
                                                        $order->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
4✔
476
                                                }
477
                                        }
478
                                        break;
4✔
479
                                default:
480
                                        $prop = \wc_graphql_camel_case_to_underscore( $key );
4✔
481
                                        if ( is_callable( [ $order, "set_{$prop}" ] ) ) {
4✔
482
                                                $order->{"set_{$prop}"}( $value );
4✔
483
                                        }
484
                                        break;
4✔
485
                        }//end switch
486
                }//end foreach
487

488
                /**
489
                 * Action called before changes to order meta are saved.
490
                 *
491
                 * @param \WC_Order                            $order   WC_Order instance.
492
                 * @param array                                $props   Order props array.
493
                 * @param \WPGraphQL\AppContext                $context Request AppContext instance.
494
                 * @param \GraphQL\Type\Definition\ResolveInfo $info    Request ResolveInfo instance.
495
                 */
496
                do_action( 'graphql_woocommerce_before_order_meta_save', $order, $input, $context, $info );
4✔
497

498
                $order->save_meta_data();
4✔
499
                $order->save();
4✔
500
        }
501

502
        /**
503
         * Update address.
504
         *
505
         * @param array   $address   Address data.
506
         * @param integer $order_id  WC_Order instance.
507
         * @param string  $type      Address type.
508
         *
509
         * @throws \Exception  Failed to retrieve order.
510
         *
511
         * @return void
512
         */
513
        protected static function update_address( $address, $order_id, $type = 'billing' ) {
514
                $order = \WC_Order_Factory::get_order( $order_id );
4✔
515
                if ( ! is_object( $order ) ) {
4✔
516
                        throw new \Exception( __( 'Failed to retrieve order.', 'wp-graphql-woocommerce' ) );
×
517
                }
518

519
                $formatted_address = Customer_Mutation::address_input_mapping( $address, $type );
4✔
520
                foreach ( $formatted_address as $key => $value ) {
4✔
521
                        if ( is_callable( [ $order, "set_{$type}_{$key}" ] ) ) {
4✔
522
                                $order->{"set_{$type}_{$key}"}( $value );
4✔
523
                        }
524
                }
525
                $order->save();
4✔
526
        }
527

528
        /**
529
         * Applies coupons to WC_Order instance
530
         *
531
         * @param int   $order_id  Order ID.
532
         * @param array $coupons   Coupon codes to be applied to order.
533
         *
534
         * @throws \Exception  Failed to retrieve order.
535
         *
536
         * @return void
537
         */
538
        public static function apply_coupons( $order_id, $coupons ) {
539
                $order = \WC_Order_Factory::get_order( $order_id );
4✔
540
                if ( ! is_object( $order ) ) {
4✔
541
                        throw new \Exception( __( 'Failed to retrieve order.', 'wp-graphql-woocommerce' ) );
×
542
                }
543

544
                // Remove all coupons first to ensure calculation is correct.
545
                foreach ( $order->get_items( 'coupon' ) as $coupon ) {
4✔
546
                        /**
547
                         * Order item coupon.
548
                         *
549
                         * @var \WC_Order_Item_Coupon $coupon
550
                         */
551

552
                        $order->remove_coupon( $coupon->get_code() );
1✔
553
                }
554

555
                foreach ( $coupons as $code ) {
4✔
556
                        $results = $order->apply_coupon( sanitize_text_field( $code ) );
4✔
557
                        if ( is_wp_error( $results ) ) {
4✔
558
                                do_action( 'graphql_woocommerce_' . $results->get_error_code(), $results, $code, $coupons, $order );
×
559
                        }
560
                }
561

562
                $order->save();
4✔
563
        }
564

565
        /**
566
         * Validates order customer
567
         *
568
         * @param array $input  Input data describing order.
569
         *
570
         * @return bool
571
         */
572
        public static function validate_customer( $input ) {
573
                if ( ! empty( $input['customerId'] ) ) {
4✔
574
                        // Make sure customer exists.
575
                        if ( false === get_user_by( 'id', $input['customerId'] ) ) {
4✔
576
                                return false;
×
577
                        }
578
                        // Make sure customer is part of blog.
579
                        if ( is_multisite() && ! is_user_member_of_blog( $input['customerId'] ) ) {
4✔
580
                                add_user_to_blog( get_current_blog_id(), $input['customerId'], 'customer' );
×
581
                        }
582

583
                        return true;
4✔
584
                }
585

586
                return false;
×
587
        }
588

589
        /**
590
         * Purge object when creating.
591
         *
592
         * @param null|\WC_Order|\WPGraphQL\WooCommerce\Model\Order $order         Object data.
593
         * @param boolean                                           $force_delete  Delete or put in trash.
594
         *
595
         * @return bool
596
         * @throws \GraphQL\Error\UserError  Failed to delete order.
597
         */
598
        public static function purge( $order, $force_delete = true ) {
599
                if ( ! empty( $order ) ) {
1✔
600
                        return $order->delete( $force_delete );
1✔
601
                }
602

603
                return false;
×
604
        }
605
}
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