guard( 'manage_options', 'manage_woocommerce' ); if ( $check ) { return $check; } if ( $location_id <= 0 ) { return [ 'error' => 'location_id must be a positive integer.' ]; } try { $request = new \WP_REST_Request( 'GET', '/wpcafe/v2/locations/' . $location_id ); $request->set_url_params( [ 'id' => $location_id ] ); $controller = new \WpCafe\Location\Controllers\Location_Controller(); $result = $this->extract_response( $controller->get_item( $request ), 'Location not found.' ); if ( isset( $result['error'] ) ) { return $result; } return $this->shape_location( $result ); } catch ( \Throwable $e ) { Log::error( 'Wpcafe_Get_Location_Tool error', [ 'error' => $e->getMessage() ] ); return [ 'error' => 'Failed to retrieve location: ' . $e->getMessage() ]; } } /** * Curate a Location_Resource record down to the fields the LLM needs, * dropping the large schedule and table-layout blobs. * * @param array $location Raw location record. * @return array */ private function shape_location( array $location ): array { return [ 'id' => $location['term_id'] ?? null, 'restaurant_name' => $location['restaurant_name'] ?? '', 'location' => $location['location'] ?? '', 'status' => $location['status'] ?? '', 'enable_pickup' => $location['enable_pickup'] ?? '', 'enable_delivery' => $location['enable_delivery'] ?? '', 'enable_reservation' => $location['enable_reservation'] ?? '', 'delivery_fee' => $location['delivery_fee'] ?? 0, 'delivery_minimum_order_amount' => $location['delivery_minimum_order_amount'] ?? 0, 'pickup_minimum_order_amount' => $location['pickup_minimum_order_amount'] ?? 0, 'reservation_status' => $location['reservation_status'] ?? '', 'reservation_minimum_guest' => $location['reservation_minimum_guest'] ?? 0, 'reservation_maximum_guest' => $location['reservation_maximum_guest'] ?? 0, ]; } }