public function status_updated($request_id, $status) { global $wpdb; $order_id = get_post_meta($request_id, '_order_id', true); $triggers = array('warranty_status'); $emails = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}followup_emails WHERE `interval_type` = 'warranty_status' AND status = 1"); foreach ($emails as $email) { $interval = (int) $email->interval_num; if ($email->interval_type == 'date') { if (!empty($email->send_date_hour) && !empty($email->send_date_minute)) { $send_on = strtotime($email->send_date . ' ' . $email->send_date_hour . ':' . $email->send_date_minute); if (false === $send_on) { // fallback to only using the date $send_on = strtotime($email->send_date); } } else { $send_on = strtotime($email->send_date); } } else { $add = FUE::get_time_to_add($interval, $email->interval_duration); $send_on = current_time('timestamp') + $add; } $insert = array('send_on' => $send_on, 'email_id' => $email->id, 'user_id' => 0, 'order_id' => $order_id, 'is_cart' => 0); FUE::insert_email_order($insert); // Tell FUE that an email order has been created // to stop it from sending generic emails if (!defined('FUE_ORDER_CREATED')) { define('FUE_ORDER_CREATED', true); } } FUE_Woocommerce::create_email_orders($triggers, $order_id); }
public function replace($matches) { if (empty($matches)) { return ''; } $url = $matches[1]; return FUE::create_email_url($this->email_order_id, $this->email_id, $this->user_id, $this->user_email, $url); }
public function status_updated($request_id, $status) { $order_id = get_post_meta($request_id, '_order_id', true); $triggers = array('warranty_status'); FUE::create_order_from_triggers($order_id, $triggers); }
public function after_points_increased($user_id, $points, $event_type, $data = null, $order_id = 0) { global $wpdb; $emails = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}followup_emails WHERE `interval_type` IN ('points_earned', 'points_greater_than')"); foreach ($emails as $email) { $interval = (int) $email->interval_num; if ($email->interval_type == 'points_greater_than') { $meta = maybe_unserialize($email->meta); if ($points < $meta['points_greater_than']) { continue; } } if ($email->interval_type == 'date') { if (!empty($email->send_date_hour) && !empty($email->send_date_minute)) { $send_on = strtotime($email->send_date . ' ' . $email->send_date_hour . ':' . $email->send_date_minute); if (false === $send_on) { // fallback to only using the date $send_on = strtotime($email->send_date); } } else { $send_on = strtotime($email->send_date); } } else { $add = FUE::get_time_to_add($interval, $email->interval_duration); $send_on = current_time('timestamp') + $add; } $insert = array('send_on' => $send_on, 'email_id' => $email->id, 'user_id' => $user_id, 'order_id' => 0, 'is_cart' => 0); $email_order_id = FUE::insert_email_order($insert); $data = array('user_id' => $user_id, 'points' => $points, 'event_type' => $event_type); update_option('fue_email_order_' . $email_order_id, $data); } }
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); }
echo '<li><a href="#' . $key . '_mails" class="' . $cls . '">' . $type . '</a>'; if ($i < $num) { echo '|'; } echo '</li>'; } ?> <?php do_action('fue_email_types_sub'); ?> </ul> <br class="clear"> <?php foreach ($types as $key => $type) { $mails = FUE::get_emails($key); $bcc = isset($bccs[$key]) ? $bccs[$key] : ''; // Manual Emails if ($key == 'manual') { ?> <div class="section" id="manual_mails" style="display:none;"> <h3><?php _e('Manual Emails', 'follow_up_emails'); ?> </h3> <p class="description">Manual emails allow you to create email templates for you and your team to utilize when you need to send emails immediately to customers or prospective customers. Creating a manual email will allow you to reduce manual entry and duplication when you send emails from your email client, and keep emails consistent. Below are the existing Manual emails set up for your store.</p><br /> <p> <?php _e('Send a copy of all emails of this type to:', 'follow_up_emails');
/** * @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); } } }
public function set_reminders($order_id) { global $woocommerce, $wpdb; // load reminder emails $emails = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}followup_emails WHERE `interval_type` IN ('before_tribe_event_starts', 'after_tribe_event_ends') AND status = 1 ORDER BY `priority` ASC"); $tickets = array(); if (empty($emails)) { return; } $has_tickets = get_post_meta($order_id, '_tribe_has_tickets', true); $order = new WC_Order($order_id); $items = $order->get_items(); foreach ($items as $item) { $ticket_id = isset($item['id']) ? $item['id'] : $item['product_id']; // if $item is a ticket, load the event where the ticket is attached to $event_id = get_post_meta($ticket_id, '_tribe_wooticket_for_event', true); if (!$event_id) { continue; } if (!in_array($ticket_id, $tickets)) { $tickets[] = $ticket_id; } } $now = current_time('timestamp'); foreach ($emails as $email) { $interval = (int) $email->interval_num; $add = FUE::get_time_to_add($interval, $email->interval_duration); foreach ($tickets as $ticket_id) { $event_id = get_post_meta($ticket_id, '_tribe_wooticket_for_event', true); if ($email->interval_type == 'before_tribe_event_starts') { $start = get_post_meta($event_id, '_EventStartDate', true); if (empty($start)) { continue; } $start = strtotime($start); // check if a limit is in place if (isset($email->meta['tribe_limit'], $email->meta['tribe_limit_days']) && !empty($tribe_limit_days)) { $days = ($start - $now) / 86400; if ($days <= $email->meta['tribe_limit_days']) { // $days is within limit - skip continue; } } $send_on = $start - $add; // if send_on is in the past, do not queue it if ($now > $send_on) { continue; } } else { $end = get_post_meta($event_id, '_EventEndDate', true); if (empty($end)) { continue; } $end = strtotime($end); $send_on = $end + $add; // if send_on is in the past, do not queue it if ($now > $send_on) { continue; } } $insert = array('user_id' => $order->user_id, 'order_id' => $order_id, 'product_id' => $ticket_id, 'email_id' => $email->id, 'send_on' => $send_on); FUE::insert_email_order($insert); } } }
public function quiz_grade($user_id, $quiz_id, $grade, $passmark) { global $wpdb; $types = "'quiz_completed'"; if ($grade >= $passmark) { $types .= ",'quiz_passed'"; } else { $types .= ",'quiz_failed'"; } $emails = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}followup_emails WHERE interval_type IN ({$types}) AND status = 1"); $user = new WP_User($user_id); foreach ($emails as $email) { $values = array('user_id' => $user_id, 'meta' => array('quiz_id' => $quiz_id, 'grade' => $grade, 'passmark' => $passmark)); FUE::queue_email($values, $email); } }
function import_orders() { FUE::import_orders($_POST['email_id']); }
public function email_replacements($reps, $email_data, $email_order, $email_row) { global $wpdb, $woocommerce; $email_type = $email_row->email_type; $order_date = ''; $order_datetime = ''; $order_id = ''; if ($email_order->order_id) { $order = new WC_Order($email_order->order_id); $order_date = date(get_option('date_format'), strtotime($order->order_date)); $order_datetime = date(get_option('date_format') . ' ' . get_option('time_format'), strtotime($order->order_date)); $order_id = apply_filters('woocommerce_order_number', '#' . $email_order->order_id, $order); } if ($email_type == 'generic') { if ($email_order->order_id) { $used_cats = array(); $item_list = '<ul>'; $item_cats = '<ul>'; $items = $order->get_items(); foreach ($items as $item) { $item_id = isset($item['product_id']) ? $item['product_id'] : $item['id']; $item_list .= apply_filters('fue_email_item_list', '<li><a href="' . FUE::create_email_url($email_order->id, $email_row->id, $email_data['user_id'], $email_data['email_to'], get_permalink($item_id)) . '">' . get_the_title($item_id) . '</a></li>', $email_order->id, $item); $cats = get_the_terms($item_id, 'product_cat'); if (is_array($cats) && !empty($cats)) { foreach ($cats as $cat) { if (!in_array($cat->term_id, $used_cats)) { $item_cats .= apply_filters('fue_email_cat_list', '<li>' . $cat->name . '</li>', $email_order->id, $cat); } } } } $item_list .= '</ul>'; $item_cats .= '</ul>'; } else { $item_list = ''; $item_cats = ''; } $reps = array_merge($reps, array($order_id, $order_date, $order_datetime, $email_data['first_name'], $email_data['first_name'] . ' ' . $email_data['last_name'], $email_data['email_to'], $item_list, $item_cats)); } elseif ($email_type == 'customer') { if ($email_data['user_id'] > 0) { $customer = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}followup_customers WHERE user_id = %d", $email_data['user_id'])); $spent_order = woocommerce_price($order->order_total); $spent_total = woocommerce_price($customer->total_purchase_price); $num_orders = $customer->total_orders; $last_order_date = $wpdb->get_var($wpdb->prepare("SELECT p.post_date FROM {$wpdb->posts} p, {$wpdb->prefix}followup_customer_orders co WHERE co.followup_customer_id = %d AND co.order_id = p.ID AND p.post_status = 'publish' ORDER BY p.ID DESC LIMIT 1", $email_data['user_id'])); $last_purchase = date(get_option('date_format'), strtotime($last_order_date)); } else { $customer = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}followup_customers WHERE email_address = %s", $email_data['email_to'])); $spent_order = woocommerce_price($order->order_total); $spent_total = woocommerce_price($customer->total_purchase_price); $num_orders = $customer->total_orders; $last_order_date = $wpdb->get_var($wpdb->prepare("SELECT p.post_date FROM {$wpdb->posts} p, {$wpdb->postmeta} pm WHERE pm.meta_key = '_billing_email' AND pm.meta_value = %d AND pm.post_id = p.ID AND p.post_status = 'publish' ORDER BY p.ID DESC LIMIT 1", $email_data['email_to'])); $last_purchase = date(get_option('date_format'), strtotime($last_order_date)); } $reps = array_merge($reps, array($order_id, $order_date, $order_datetime, $email_data['first_name'], $email_data['first_name'] . ' ' . $email_data['last_name'], $email_data['email_to'], $spent_order, $spent_total, $num_orders, $last_purchase)); } elseif ($email_type == 'normal' || $email_type == 'reminder') { $categories = ''; if (!empty($email_order->product_id)) { $item = function_exists('get_product') ? get_product($email_order->product_id) : new WC_Product($email_order->product_id); $cats = get_the_terms($item->id, 'product_cat'); if (is_array($cats) && !empty($cats)) { foreach ($cats as $cat) { $categories .= $cat->name . ', '; } $categories = rtrim($categories, ', '); } } $item_url = FUE::create_email_url($email_order->id, $email_order->id, $email_data['user_id'], $email_data['email_to'], get_permalink($item->id)); if (!empty($codes)) { add_query_arg($codes, $item_url); } $order_id = ''; if (0 != $email_order->order_id) { $order_id = apply_filters('woocommerce_order_number', '#' . $email_order->order_id, $order); } $reps = array_merge($reps, array($order_id, $order_date, $order_datetime, $email_data['first_name'], $email_data['first_name'] . ' ' . $email_data['last_name'], $email_data['email_to'], '<a href="' . $item_url . '">' . get_the_title($item->id) . '</a>', $categories)); } return $reps; }
public static function ajax_clone_email() { $id = $_POST['id']; $name = $_POST['name']; $new_email_id = FUE::clone_email($id, $name); if (!is_wp_error($new_email_id)) { $resp = array('status' => 'OK', 'id' => $new_email_id, 'url' => 'admin.php?page=followup-emails-form&step=1&id=' . $new_email_id); } else { $resp = array('status' => 'ERROR', 'message' => $new_email_id->get_error_message()); } die(json_encode($resp)); }
public static function suspended_subscription($user_id, $subs_key) { global $wpdb; $parts = explode('_', $subs_key); $order_id = $parts[0]; $item_id = $parts[1]; $order = new WC_Order($order_id); $items = $order->get_items(); $order_created = false; $triggers[] = 'subs_suspended'; FUE::create_order_from_triggers($order_id, $triggers); }
public static function queue_email($values, $email) { $defaults = array('user_id' => '', 'user_email' => '', 'is_cart' => 0, 'meta' => ''); $values = wp_parse_args($values, $defaults); $values['send_on'] = self::get_email_send_timestamp($email); $values['email_id'] = $email->id; FUE::insert_email_order($values); }
function user_register($user_id) { global $wpdb; $triggers = apply_filters('fue_user_register_triggers', array('signup'), $user_id); FUE::create_order_from_signup($user_id, $triggers); }
public static function set_renewal_reminder($user_id, $subs_key) { global $wpdb; $parts = explode('_', $subs_key); $order_id = $parts[0]; $order = new WC_Order($order_id); if (WC_Subscriptions_Order::order_contains_subscription($order)) { // look for renewal emails $emails = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}followup_emails WHERE `interval_type` = 'subs_before_renewal'"); if (count($emails) > 0) { $item = WC_Subscriptions_Order::get_item_by_product_id($order); $item_id = WC_Subscriptions_Order::get_items_product_id($item); $renewal = WC_Subscriptions_Order::get_next_payment_timestamp($order, $item_id); if (0 == $renewal) { return; } foreach ($emails as $email) { // add this email to the queue $interval = (int) $email->interval_num; $add = FUE::get_time_to_add($interval, $email->interval_duration); $send_on = $renewal - $add; $insert = array('send_on' => $send_on, 'email_id' => $email->id, 'product_id' => 0, 'order_id' => $order_id); FUE::insert_email_order($insert); } } } }