/** * Access API Correios. * * @param string $tracking_code. * * @return SimpleXMLElement|stdClass History Tracking code. */ protected function get_tracking_history($tracking_code) { $user_data = $this->get_user_data(); $args = apply_filters('woocommerce_correios_tracking_args', array('Usuario' => $user_data['login'], 'Senha' => $user_data['password'], 'Tipo' => 'L', 'Resultado' => 'T', 'Objetos' => $tracking_code)); $api_url = $this->get_tracking_history_api_url(); $request_url = add_query_arg($args, $api_url); $params = array('timeout' => 30); $this->logger('Requesting tracking history in: ' . print_r($request_url, true)); $response = wp_safe_remote_get($request_url, $params); if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) { try { $tracking_history = WC_Correios_Connect::safe_load_xml($response['body'], LIBXML_NOCDATA); } catch (Exception $e) { $this->logger('Tracking history invalid XML: ' . $e->getMessage()); } } else { $tracking_history = new stdClass(); $tracking_history->error = true; } $this->logger('Tracking history response: ' . print_r($tracking_history, true)); return $tracking_history; }