/** * send notify email for limit of sms credits */ function do_sms_limit_notify() { // do something every day $sms_limit = isset($this->customizations['ws_sms_credits_limit']) ? $this->customizations['ws_sms_credits_limit'] : 0; $sms_limit_email = isset($this->customizations['ws_sms_credits_notify_email']) ? $this->customizations['ws_sms_credits_notify_email'] : ''; $notify_status = isset($this->customizations['ws_sms_credits_notify']) ? $this->customizations['ws_sms_credits_notify'] : 'no'; $current_sms_num = WC_Sendinblue::ws_get_credits(); if ($notify_status == 'yes' && $sms_limit_email != '' && $sms_limit != 0 && $current_sms_num < $sms_limit) { $subject = __('Notification of your credits', 'wc_sendinblue'); WC_Sendinblue_SMTP::send_email('notify', $sms_limit_email, $subject, $current_sms_num); } }
/** * 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; }
/** ajax module for get statistics regarding date range */ public static function ajax_get_daterange() { $general_settings = get_option('ws_main_option', array()); if (!class_exists('Mailin')) { require_once 'includes/mailin.php'; } $mailin = new Mailin(WC_Sendinblue::sendinblue_api_url, $general_settings['access_key']); $begin = new DateTime($_POST['begin']); //Date $end = new DateTime($_POST['end']); if ($begin == $end) { $begin = $begin->modify('+1 day'); $end = $end->modify('+2 day'); } else { $begin = $begin->modify('+1 day'); $end = $end->modify('+1 day'); } $begin = $begin->format("Y-m-d"); $end = $end->format("Y-m-d"); $statistics = WC_Sendinblue::get_statistics($mailin, $begin, $end); echo json_encode($statistics); die; }