• 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

93.55
/includes/mutation/class-cart-empty.php
1
<?php
2
/**
3
 * Mutation - emptyCart
4
 *
5
 * Registers mutation for empty cart of all contents including coupons and fees.
6
 *
7
 * @package WPGraphQL\WooCommerce\Mutation
8
 * @since 0.1.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\WooCommerce\Data\Mutation\Cart_Mutation;
17

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

40
        /**
41
         * Defines the mutation output field configuration
42
         *
43
         * @return array
44
         */
45
        public static function get_output_fields() {
46
                return [
296✔
47
                        'deletedCart' => Cart_Mutation::get_cart_field(),
296✔
48
                        'cart'        => [
296✔
49
                                'type'    => 'Cart',
296✔
50
                                'resolve' => static function () {
296✔
51
                                        return \WC()->cart;
×
52
                                },
296✔
53
                        ],
296✔
54
                ];
296✔
55
        }
56

57
        /**
58
         * Defines the mutation data modification closure.
59
         *
60
         * @return callable
61
         */
62
        public static function mutate_and_get_payload() {
63
                return static function ( $input, AppContext $context, ResolveInfo $info ) {
296✔
64
                        Cart_Mutation::check_session_token();
2✔
65

66
                        // Get/Clone WC_Cart instance.
67
                        $cloned_cart = clone \WC()->cart;
1✔
68

69
                        if ( $cloned_cart->is_empty() ) {
1✔
NEW
70
                                throw new UserError( __( 'Cart is empty', 'graphql-for-ecommerce' ) );
×
71
                        }
72

73
                        /**
74
                         * Action fired before cart was cleared/emptied.
75
                         *
76
                         * @param object      $cloned_cart Cloned cart.
77
                         * @param array       $input       Input info.
78
                         * @param \WPGraphQL\AppContext  $context     Context passed.
79
                         * @param \GraphQL\Type\Definition\ResolveInfo $info        Resolver info passed.
80
                         */
81
                        do_action( 'graphql_woocommerce_before_empty_cart', $cloned_cart, $input, $context, $info );
1✔
82

83
                        // Empty cart.
84
                        $clear_persistent_cart = ! empty( $input['clearPersistentCart'] ) ? $input['clearPersistentCart'] : true;
1✔
85
                        \WC()->cart->empty_cart( $clear_persistent_cart );
1✔
86

87
                        /**
88
                         * Action fired after cart was cleared/emptied.
89
                         *
90
                         * @param object      $cloned_cart Cloned cart.
91
                         * @param array       $input       Input info.
92
                         * @param \WPGraphQL\AppContext  $context     Context passed.
93
                         * @param \GraphQL\Type\Definition\ResolveInfo $info        Resolver info passed.
94
                         */
95
                        do_action( 'graphql_woocommerce_after_empty_cart', $cloned_cart, $input, $context, $info );
1✔
96

97
                        do_action( 'woographql_update_session', true );
1✔
98

99
                        return [ 'cart' => $cloned_cart ];
1✔
100
                };
296✔
101
        }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc