| @@ 97-113 (lines=17) @@ | ||
| 94 | * @param WP_REST_Request $request |
|
| 95 | * @return WP_Error|WP_REST_Response |
|
| 96 | */ |
|
| 97 | public function get_items( $request ) { |
|
| 98 | $settings = $this->get_group_settings( $request['group'] ); |
|
| 99 | ||
| 100 | if ( is_wp_error( $settings ) ) { |
|
| 101 | return $settings; |
|
| 102 | } |
|
| 103 | ||
| 104 | $data = array(); |
|
| 105 | ||
| 106 | foreach ( $settings as $setting_obj ) { |
|
| 107 | $setting = $this->prepare_item_for_response( $setting_obj, $request ); |
|
| 108 | $setting = $this->prepare_response_for_collection( $setting ); |
|
| 109 | $data[] = $setting; |
|
| 110 | } |
|
| 111 | ||
| 112 | return rest_ensure_response( $data ); |
|
| 113 | } |
|
| 114 | ||
| 115 | /** |
|
| 116 | * Get all settings in a group. |
|
| @@ 51-68 (lines=18) @@ | ||
| 48 | * @param WP_REST_Request $request |
|
| 49 | * @return WP_REST_Response|WP_Error |
|
| 50 | */ |
|
| 51 | public function get_items( $request ) { |
|
| 52 | $zone = $this->get_zone( $request['id'] ); |
|
| 53 | ||
| 54 | if ( is_wp_error( $zone ) ) { |
|
| 55 | return $zone; |
|
| 56 | } |
|
| 57 | ||
| 58 | $locations = $zone->get_zone_locations(); |
|
| 59 | $data = array(); |
|
| 60 | ||
| 61 | foreach ( $locations as $location_obj ) { |
|
| 62 | $location = $this->prepare_item_for_response( $location_obj, $request ); |
|
| 63 | $location = $this->prepare_response_for_collection( $location ); |
|
| 64 | $data[] = $location; |
|
| 65 | } |
|
| 66 | ||
| 67 | return rest_ensure_response( $data ); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * Update all Shipping Zone Locations. |
|
| @@ 110-126 (lines=17) @@ | ||
| 107 | * @param WP_REST_Request $request |
|
| 108 | * @return WP_REST_Response|WP_Error |
|
| 109 | */ |
|
| 110 | public function get_items( $request ) { |
|
| 111 | $zone = $this->get_zone( $request['zone_id'] ); |
|
| 112 | ||
| 113 | if ( is_wp_error( $zone ) ) { |
|
| 114 | return $zone; |
|
| 115 | } |
|
| 116 | ||
| 117 | $methods = $zone->get_shipping_methods(); |
|
| 118 | $data = array(); |
|
| 119 | ||
| 120 | foreach ( $methods as $method_obj ) { |
|
| 121 | $method = $this->prepare_item_for_response( $method_obj, $request ); |
|
| 122 | $data[] = $method; |
|
| 123 | } |
|
| 124 | ||
| 125 | return rest_ensure_response( $data ); |
|
| 126 | } |
|
| 127 | ||
| 128 | /** |
|
| 129 | * Create a new shipping zone method instance. |
|