• 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

94.03
/includes/mutation/class-shipping-zone-method-remove.php
1
<?php
2
/**
3
 * Mutation - removeMethodFromShippingZone
4
 *
5
 * Registers mutation for removing a shipping method from a shipping zone.
6
 *
7
 * @package WPGraphQL\WooCommerce\Mutation
8
 * @since 0.20.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\Model\Shipping_Method;
17

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

38
        /**
39
         * Defines the mutation input field configuration
40
         *
41
         * @return array
42
         */
43
        public static function get_input_fields() {
44
                return [
296✔
45
                        'zoneId'     => [
296✔
46
                                'type'        => [ 'non_null' => 'Int' ],
296✔
47
                                'description' => static function () {
296✔
48
                                        return __( 'The ID of the shipping zone to delete.', 'graphql-for-ecommerce' );
2✔
49
                                },
296✔
50
                        ],
296✔
51
                        'instanceId' => [
296✔
52
                                'type'        => [ 'non_null' => 'Int' ],
296✔
53
                                'description' => static function () {
296✔
54
                                        return __( 'Shipping method instance ID', 'graphql-for-ecommerce' );
2✔
55
                                },
296✔
56
                        ],
296✔
57
                ];
296✔
58
        }
59

60
        /**
61
         * Defines the mutation output field configuration
62
         *
63
         * @return array
64
         */
65
        public static function get_output_fields() {
66
                return [
296✔
67
                        'shippingZone'  => [
296✔
68
                                'type'    => 'ShippingZone',
296✔
69
                                'resolve' => static function ( $payload, array $args, AppContext $context ) {
296✔
70
                                        return $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] );
1✔
71
                                },
296✔
72
                        ],
296✔
73
                        'removedMethod' => [
296✔
74
                                'type'    => 'ShippingZoneToShippingMethodConnectionEdge',
296✔
75
                                'resolve' => static function ( $payload, array $args, AppContext $context ) {
296✔
76
                                        return [
1✔
77
                                                // Call the Shipping_Method constructor directly because "$payload['method']" is a non-scalar value.
78
                                                'node'   => new Shipping_Method( $payload['method'] ),
1✔
79
                                                'source' => $context->get_loader( 'shipping_zone' )->load( $payload['zone_id'] ),
1✔
80
                                        ];
1✔
81
                                },
296✔
82
                        ],
296✔
83
                ];
296✔
84
        }
85

86
        /**
87
         * Defines the mutation data modification closure.
88
         *
89
         * @return callable
90
         */
91
        public static function mutate_and_get_payload() {
92
                return static function ( $input, AppContext $context, ResolveInfo $info ) {
296✔
93
                        if ( ! \wc_shipping_enabled() ) {
1✔
NEW
94
                                throw new UserError( __( 'Shipping is disabled.', 'graphql-for-ecommerce' ), 404 );
×
95
                        }
96

97
                        if ( ! \wc_rest_check_manager_permissions( 'settings', 'delete' ) ) {
1✔
98
                                throw new UserError( __( 'Sorry, you are not allowed to remove shipping methods', 'graphql-for-ecommerce' ), \rest_authorization_required_code() );
1✔
99
                        }
100

101
                        $instance_id = $input['instanceId'];
1✔
102
                        $zone_id     = $input['zoneId'];
1✔
103
                        /** @var \WC_Shipping_Zone|false $zone */
104
                        $zone = \WC_Shipping_Zones::get_zone_by( 'zone_id', $zone_id );
1✔
105

106
                        if ( false === $zone ) {
1✔
NEW
107
                                throw new UserError( __( 'Invalid shipping zone ID.', 'graphql-for-ecommerce' ) );
×
108
                        }
109

110
                        if ( 0 === $zone->get_id() ) {
1✔
NEW
111
                                throw new UserError( __( 'Invalid shipping zone ID.', 'graphql-for-ecommerce' ) );
×
112
                        }
113

114
                        $methods = $zone->get_shipping_methods();
1✔
115
                        $method  = false;
1✔
116

117
                        foreach ( $methods as $shipping_method ) {
1✔
118
                                if ( $shipping_method->instance_id === $instance_id ) {
1✔
119
                                        $method = $shipping_method;
1✔
120
                                        break;
1✔
121
                                }
122
                        }
123

124
                        if ( ! $method ) {
1✔
NEW
125
                                throw new UserError( __( 'Invalid shipping method instance ID.', 'graphql-for-ecommerce' ) );
×
126
                        }
127

128
                        /**
129
                         * Filter shipping method object before it's removed from the shipping zone.
130
                         *
131
                         * @param \WC_Shipping_Method $method  The shipping method to be deleted.
132
                         * @param \WC_Shipping_Zone   $zone    The shipping zone object.
133
                         * @param array               $input   Request input.
134
                         */
135
                        $method = apply_filters( 'graphql_woocommerce_shipping_zone_method_add', $method, $zone, $input );
1✔
136

137
                        $zone->delete_shipping_method( $instance_id );
1✔
138

139
                        return [
1✔
140
                                'zone_id' => $zone_id,
1✔
141
                                'zone'    => $zone,
1✔
142
                                'method'  => $method,
1✔
143
                        ];
1✔
144
                };
296✔
145
        }
146
}
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