public static function send_summary()
    {
        global $wpdb;
        $last_send = get_option('fue_last_summary', 0);
        $next_send = get_option('fue_next_summary', 0);
        $now = current_time('timestamp');
        $reports = '';
        if ($now < $next_send) {
            return;
        }
        $sfn_reports = $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}followup_email_orders` WHERE `is_sent` = 1 AND `date_sent` >= %s", date('Y-m-d H:i:s', $last_send)));
        if (empty($sfn_reports)) {
            return;
        }
        foreach ($sfn_reports as $report) {
            $product_str = 'n/a';
            $order_str = 'n/a';
            $coupon_str = '-';
            $order = false;
            $email = $wpdb->get_row("SELECT * FROM `{$wpdb->prefix}followup_emails` WHERE `id` = {$report->email_id}");
            if ($report->product_id != 0) {
                $product_str = '<a href="' . get_permalink($report->product_id) . '">' . get_the_title($report->product_id) . '</a>';
            }
            if (!empty($report->coupon_name) && !empty($report->coupon_code)) {
                $coupon_str = $report->coupon_name . ' (' . $report->coupon_code . ')';
            }
            $email_address = '';
            if ($email->email_type == 'manual') {
                $meta = maybe_unserialize($report->meta);
                $email_address = $meta['email_address'];
            } else {
                $user = new WP_User($report->user_id);
                $email_address = $user->user_email;
            }
            $email_address = apply_filters('fue_report_email_address', $email_address, $report);
            $order_str = apply_filters('fue_report_order_str', '', $report);
            $reports .= '
            <tr>
                <td style="font-size: 11px; text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $email->name . '</td>
                <td style="font-size: 11px; text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $email_address . '</td>
                <td style="font-size: 11px; text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $product_str . '</td>
                <td style="font-size: 11px; text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $order_str . '</td>
                <td style="font-size: 11px; text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $report->email_trigger . '</td>
                <td style="font-size: 11px; text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $coupon_str . '</td>
            </tr>';
        }
        $body = '<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
	<thead>
		<tr>
			<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Email Name', 'follow_up_emails') . '</th>
			<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Email Address', 'follow_up_emails') . '</th>
			<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Product', 'follow_up_emails') . '</th>
			<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Order', 'follow_up_emails') . '</th>
            <th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Trigger', 'follow_up_emails') . '</th>
			<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Sent Coupon', 'follow_up_emails') . '</th>
		</tr>
	</thead>
	<tbody>
		' . $reports . '
	</tbody>
</table>';
        // send the email
        $subject = __('Follow-up emails summary', 'follow_up_emails');
        $recipient = get_option('fue_daily_emails', false);
        if (!$recipient) {
            $recipient = get_bloginfo('admin_email');
        }
        FUE::mail($recipient, $subject, $body);
        update_option('fue_last_summary', current_time('timestamp'));
        update_option('fue_next_summary', current_time('timestamp') + 86400);
    }
 /**
  * @param WC_Order $order
  */
 public function payment_failed_for_order($order)
 {
     if (1 == get_option('fue_subscription_failure_notification', 0)) {
         // notification enabled
         $emails_string = get_option('fue_subscription_failure_notification_emails', '');
         if (empty($emails_string)) {
             return;
         }
         // get the product id to get the subscription string
         $order_items = WC_Subscriptions_Order::get_recurring_items($order);
         $first_order_item = reset($order_items);
         $product_id = WC_Subscriptions_Order::get_items_product_id($first_order_item);
         $subs_key = WC_Subscriptions_Manager::get_subscription_key($order->id, $product_id);
         $subject = sprintf(__('Subscription payment failed for Order %s'), $order->get_order_number());
         $message = sprintf(__('A subscription payment for the order %s has failed. The subscription has now been automatically put on hold.'), $order->get_order_number());
         $recipients = array();
         if (strpos($emails_string, ',') !== false) {
             $recipients = array_map('trim', explode(',', $emails_string));
         } else {
             $recipients = array($emails_string);
         }
         foreach ($recipients as $email) {
             FUE::mail($email, $subject, $message);
         }
     }
 }