/** * Get statistics regarding to order's status */ public static function get_statistics($account, $startDate, $endDate) { $ws_notification_activation = get_option('ws_notification_activation', array()); $statistics = array(); $customization = get_option('wc_sendinblue_settings', array()); if (!isset($customization['ws_smtp_enable']) || $customization['ws_smtp_enable'] != 'yes') { return array(); } foreach ($ws_notification_activation as $template_name) { /*if($template_id == '0') continue;*/ $data = array("aggregate" => 0, "tag" => $template_name, "start_date" => $startDate, "end_date" => $endDate); $result = $account->get_statistics($data); $sent = $delivered = $open = $click = 0; foreach ($result['data'] as $data) { $sent += isset($data['requests']) ? $data['requests'] : 0; $delivered += isset($data['delivered']) ? $data['delivered'] : 0; $open += isset($data['unique_opens']) ? $data['unique_opens'] : 0; //opens $click += isset($data['unique_clicks']) ? $data['unique_clicks'] : 0; //clicks } $statistics[$template_name] = array('name' => $template_name, 'sent' => $sent, 'delivered' => $sent != 0 ? round($delivered / $sent * 100, 2) . "%" : "0%", 'open_rate' => $sent != 0 ? round($open / $sent * 100, 2) . "%" : "0%", 'click_rate' => $sent != 0 ? round($click / $sent * 100, 2) . "%" : "0%"); } self::$statistics = $statistics; return $statistics; }