@@ -26,7 +26,7 @@ public static function register_fields() {
2626 register_graphql_fields (
2727 'RootQuery ' ,
2828 [
29- 'cart ' => [
29+ 'cart ' => [
3030 'type ' => 'Cart ' ,
3131 'args ' => [
3232 'recalculateTotals ' => [
@@ -49,7 +49,7 @@ public static function register_fields() {
4949 return $ cart ;
5050 },
5151 ],
52- 'cartItem ' => [
52+ 'cartItem ' => [
5353 'type ' => 'CartItem ' ,
5454 'args ' => [
5555 'key ' => [
@@ -66,7 +66,7 @@ public static function register_fields() {
6666 return $ item ;
6767 },
6868 ],
69- 'cartFee ' => [
69+ 'cartFee ' => [
7070 'type ' => 'CartFee ' ,
7171 'args ' => [
7272 'id ' => [
@@ -83,7 +83,7 @@ public static function register_fields() {
8383 return $ fee ;
8484 },
8585 ],
86- 'coupon ' => [
86+ 'coupon ' => [
8787 'type ' => 'Coupon ' ,
8888 'description ' => __ ( 'A coupon object ' , 'wp-graphql-woocommerce ' ),
8989 'args ' => [
@@ -133,7 +133,7 @@ public static function register_fields() {
133133 return Factory::resolve_crud_object ( $ coupon_id , $ context );
134134 },
135135 ],
136- 'customer ' => [
136+ 'customer ' => [
137137 'type ' => 'Customer ' ,
138138 'description ' => __ ( 'A customer object ' , 'wp-graphql-woocommerce ' ),
139139 'args ' => [
@@ -173,7 +173,7 @@ public static function register_fields() {
173173 return Factory::resolve_session_customer ();
174174 },
175175 ],
176- 'order ' => [
176+ 'order ' => [
177177 'type ' => 'Order ' ,
178178 'description ' => __ ( 'A order object ' , 'wp-graphql-woocommerce ' ),
179179 'args ' => [
@@ -240,7 +240,7 @@ public static function register_fields() {
240240 return $ order ;
241241 },
242242 ],
243- 'productVariation ' => [
243+ 'productVariation ' => [
244244 'type ' => 'ProductVariation ' ,
245245 'description ' => __ ( 'A product variation object ' , 'wp-graphql-woocommerce ' ),
246246 'args ' => [
@@ -283,7 +283,7 @@ public static function register_fields() {
283283 return Factory::resolve_crud_object ( $ variation_id , $ context );
284284 },
285285 ],
286- 'refund ' => [
286+ 'refund ' => [
287287 'type ' => 'Refund ' ,
288288 'description ' => __ ( 'A refund object ' , 'wp-graphql-woocommerce ' ),
289289 'args ' => [
@@ -349,7 +349,7 @@ public static function register_fields() {
349349 return $ refund ;
350350 },
351351 ],
352- 'shippingMethod ' => [
352+ 'shippingMethod ' => [
353353 'type ' => 'ShippingMethod ' ,
354354 'description ' => __ ( 'A shipping method object ' , 'wp-graphql-woocommerce ' ),
355355 'args ' => [
@@ -384,7 +384,7 @@ public static function register_fields() {
384384 return Factory::resolve_shipping_method ( $ method_id );
385385 },
386386 ],
387- 'taxRate ' => [
387+ 'taxRate ' => [
388388 'type ' => 'TaxRate ' ,
389389 'description ' => __ ( 'A tax rate object ' , 'wp-graphql-woocommerce ' ),
390390 'args ' => [
@@ -419,6 +419,42 @@ public static function register_fields() {
419419 return Factory::resolve_tax_rate ( $ rate_id , $ context );
420420 },
421421 ],
422+ 'allowedCountries ' => [
423+ 'type ' => [ 'list_of ' => 'CountriesEnum ' ],
424+ 'description ' => __ ( 'Countries that the store sells to ' , 'wp-graphql-woocommerce ' ),
425+ 'resolve ' => function () {
426+ $ wc_countries = new \WC_Countries ();
427+ $ countries = $ wc_countries ->get_allowed_countries ();
428+
429+ return array_keys ( $ countries );
430+ },
431+ ],
432+ 'allowedCountryStates ' => [
433+ 'type ' => [ 'list_of ' => 'CountryState ' ],
434+ 'args ' => [
435+ 'country ' => [
436+ 'type ' => [ 'non_null ' => 'CountriesEnum ' ],
437+ 'description ' => __ ( 'Target country ' , 'wp-graphql-woocommerce ' ),
438+ ],
439+ ],
440+ 'description ' => __ ( 'Countries that the store sells to ' , 'wp-graphql-woocommerce ' ),
441+ 'resolve ' => function ( $ _ , $ args ) {
442+ $ country = $ args ['country ' ];
443+ $ wc_countries = new \WC_Countries ();
444+ $ states = $ wc_countries ->get_shipping_country_states ();
445+
446+ if ( ! empty ( $ states ) && ! empty ( $ states [ $ country ] ) ) {
447+ $ formatted_states = [];
448+ foreach ( $ states [ $ country ] as $ code => $ name ) {
449+ $ formatted_states [] = compact ( 'name ' , 'code ' );
450+ }
451+
452+ return $ formatted_states ;
453+ }
454+
455+ return [];
456+ },
457+ ],
422458 ]
423459 );
424460
0 commit comments