public function manual_type_actions() { $subscriptions = array(); $posts = get_posts(array('post_type' => 'product', 'post_status' => 'publish')); foreach ($posts as $post) { $product = sfn_get_product($post->ID); if ($product->is_type(array(WC_Subscriptions::$name, 'subscription_variation', 'variable-subscription'))) { $subscriptions[] = $product; } } ?> <div class="send-type-subscription send-type-div"> <select id="subscription_id" name="subscription_id" class="chzn-select" style="width: 400px;"> <?php foreach ($subscriptions as $subscription) { ?> <option value="<?php echo $subscription->id; ?> "><?php echo esc_html($subscription->get_title()); ?> </option> <?php } ?> </select> </div> <?php }
public function found_products($products) { foreach ($products as $id => $title) { $product = sfn_get_product($id); if (is_a($product, 'WC_Product_Subscription_Variation')) { $extra_data = ''; $identifier = '#' . $id; $attributes = $product->get_variation_attributes(); $extra_data = ' – ' . implode(', ', $attributes) . ' – ' . woocommerce_price($product->get_price()); $products[$id] = sprintf(__('%s – %s%s', 'woocommerce'), $identifier, $product->get_title(), $extra_data); } } return $products; }
/** * Send emails that are in the email queue */ public static function send_emails() { global $wpdb, $woocommerce; // get start and end times $to = current_time('timestamp'); $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}followup_email_orders` WHERE `is_sent` = 0 AND `send_on` <= %s", $to)); foreach ($results as $email_order) { $sfn_report = array(); $user_id = 0; if ($email_order->order_id != 0) { // order $order = new WC_Order($email_order->order_id); if (isset($order->user_id) && $order->user_id > 0) { $user_id = $order->user_id; $wp_user = new WP_User($order->user_id); $email_to = $wp_user->user_email; $first_name = $wp_user->first_name; $last_name = $wp_user->last_name; $cname = $first_name . ' ' . $last_name; } else { $email_to = $order->billing_email; $first_name = $order->billing_first_name; $last_name = $order->billing_last_name; } $cname = $first_name . ' ' . $last_name; $order_date = date('M d, Y h:i A', strtotime($order->order_date)); } else { $order = false; $user_id = $email_order->user_id; $wp_user = new WP_User($email_order->user_id); $email_to = $wp_user->user_email; $first_name = $wp_user->first_name; $last_name = $wp_user->last_name; $cname = $first_name . ' ' . $last_name; $order_date = ''; if (empty($first_name) && empty($last_name)) { $first_name = $wp_user->user_nicename; $cname = $wp_user->user_nicename; } // non-order related email. make sure user is not opted-out $opt_out = get_user_meta($email_order->user_id, 'wcfu_opted_out', true); $opt_out = apply_filters('fue_user_opt_out', $opt_out, $email_order->user_id); if ($opt_out) { // user opted out, delete this email_order $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}followup_email_orders WHERE `id` = %d", $email_order->id)); continue; } } $email = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}followup_emails` WHERE `id` = '%d'", $email_order->email_id)); // check if the email address is on the excludes list $sql = $wpdb->prepare("SELECT COUNT(*) FROM `{$wpdb->prefix}followup_email_excludes` WHERE `email` = '%s'", $email_to); if ($wpdb->get_var($sql) > 0) { // delete and go to the next entry do_action('fue_email_excluded', $email_to, $email_order->id); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}followup_email_orders WHERE `id` = %d", $email_order->id)); continue; } if ($email->email_type == 'generic') { if ($order) { $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="' . self::create_email_url($email_order->id, $email->id, $user_id, $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 = ''; } } else { if (!empty($email_order->product_id)) { $item = sfn_get_product($email_order->product_id); $cats = get_the_terms($item->id, 'product_cat'); $categories = ''; if (is_array($cats) && !empty($cats)) { foreach ($cats as $cat) { $categories .= $cat->name . ', '; } $categories = rtrim($categories, ', '); } } else { } } // process variable replacements $tracking = $email->tracking_code; $codes = array(); if (!empty($tracking)) { parse_str($tracking, $codes); foreach ($codes as $key => $val) { $codes[$key] = urlencode($val); } } $store_url = site_url(); $store_name = get_bloginfo('name'); $page_id = woocommerce_get_page_id('followup_unsubscribe'); $unsubscribe = add_query_arg('wcfu', $email_to, get_permalink($page_id)); // convert urls $store_url = self::create_email_url($email_order->id, $email->id, $user_id, $email_to, $store_url); $unsubscribe = self::create_email_url($email_order->id, $email->id, $user_id, $email_to, $unsubscribe); if (!empty($codes)) { $store_url = add_query_arg($codes, $store_url); $unsubscribe = add_query_arg($codes, $unsubscribe); } if ($email->email_type == 'generic') { $vars = array('{order_number}', '{order_datetime}', '{store_url}', '{store_name}', '{customer_first_name}', '{customer_name}', '{item_names}', '{item_categories}', '{unsubscribe_url}'); $reps = array(0 == $email_order->order_id ? '' : $email_order->order_id, $order_date, $store_url, $store_name, $first_name, $first_name . ' ' . $last_name, $item_list, $item_cats, $unsubscribe); } elseif ($email->email_type == 'signup') { $vars = array('{store_url}', '{store_name}', '{customer_first_name}', '{customer_name}', '{unsubscribe_url}'); $reps = array($store_url, $store_name, $first_name, $cname, $unsubscribe); } else { $item_url = self::create_email_url($email_order->id, $email->id, $user_id, $email_to, get_permalink($item->id)); if (!empty($codes)) { add_query_arg($codes, $item_url); } $vars = array('{order_number}', '{order_datetime}', '{store_url}', '{store_name}', '{customer_first_name}', '{customer_name}', '{item_name}', '{item_category}', '{unsubscribe_url}'); $reps = array(0 == $email_order->order_id ? '' : $email_order->order_id, $order_date, $store_url, $store_name, $first_name, $first_name . ' ' . $last_name, '<a href="' . $item_url . '">' . get_the_title($item->id) . '</a>', $categories, $unsubscribe); } $subject = apply_filters('fue_email_subject', $email->subject, $email, $email_order); $message = apply_filters('fue_email_message', $email->message, $email, $email_order); $subject = strip_tags(str_replace($vars, $reps, $subject)); $message = str_replace($vars, $reps, $message); // hook to variable replacement $subject = apply_filters('fue_send_email_subject', $subject, $email_order); $message = apply_filters('fue_send_email_message', $message, $email_order); // look for custom fields $message = preg_replace_callback('|\\{cf ([0-9]+) ([^}]*)\\}|', 'fue_add_custom_fields', $message); do_action('fue_before_email_send', $subject, $message, $email_order); // send the email $mailer = $woocommerce->mailer(); $message = $mailer->wrap_message($subject, $message); $mailer->send($email_to, $subject, $message); $oid = $order ? $email_order->order_id : 0; if ($email->interval_type == 'date') { $email_trigger = sprintf(__('Send on %s'), $email->send_date); } elseif ($email->interval_type == 'signup') { $email_trigger = sprintf(__('%d %s after user signs up', 'wc_followup_emails'), $email->interval_num, $email->interval_duration); } else { $email_trigger = sprintf(__('%d %s after %s'), $email->interval_num, $email->interval_duration, SFN_FollowUpEmails::get_trigger_name($email->interval_type)); } do_action('fue_after_email_sent', $subject, $message, $email_order); do_action('fue_email_sent_details', $email_order, $order->user_id, $email, $email_to, $cname, $email_trigger); // increment usage count $wpdb->query($wpdb->prepare("UPDATE `{$wpdb->prefix}followup_emails` SET `usage_count` = `usage_count` + 1 WHERE `id` = %d", $email->id)); // update the email order $now = date('Y-m-d H:i:s'); $wpdb->query($wpdb->prepare("UPDATE `{$wpdb->prefix}followup_email_orders` SET `is_sent` = 1, `date_sent` = %s, `email_trigger` = %s WHERE `id` = %d", $now, $email_trigger, $email_order->id)); do_action('fue_email_order_sent', $email_order->id); } }
/** * Send emails that are in the email queue */ public static function send_emails() { global $wpdb, $woocommerce; global $sfnFollowUpEmails; // get start and end times $to = current_time('timestamp'); $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}followup_email_orders` WHERE `is_sent` = 0 AND `send_on` <= %s", $to)); foreach ($results as $email_order) { $sfn_report = array(); $user_id = 0; if (!$email_order->email_id || $email_order->email_id == 0) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}followup_email_orders WHERE id = %d", $email_order->id)); continue; } $email = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}followup_emails` WHERE `id` = '%d'", $email_order->email_id)); // allow other extensions to "skip" sending this email $skip = apply_filters('fue_skip_email_sending', false, $email, $email_order); if ($skip) { continue; } if ($email_order->order_id != 0) { // order $order = new WC_Order($email_order->order_id); // if this is an "Order Status" email, make sure that the order is still // in the same status as the one it was originally intended for // e.g. Do not send "on-hold" order status emails if the order status has // been changed to "completed" before sending the email $order_statuses_array = (array) get_terms('shop_order_status', array('hide_empty' => 0, 'orderby' => 'id')); $all_statuses = array(); foreach ($order_statuses_array as $status) { $all_statuses[] = $status->slug; } if (in_array($email->interval_type, $all_statuses) && $email->interval_type !== $order->status) { // order status looks to have been changed already $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}followup_email_orders WHERE id = %d AND is_sent = 0", $email_order->id)); continue; } if (isset($order->user_id) && $order->user_id > 0) { $user_id = $order->user_id; $wp_user = new WP_User($order->user_id); $email_to = $wp_user->user_email; $first_name = $wp_user->first_name; $last_name = $wp_user->last_name; $cname = $first_name . ' ' . $last_name; } else { $email_to = $order->billing_email; $first_name = $order->billing_first_name; $last_name = $order->billing_last_name; } $cname = $first_name . ' ' . $last_name; $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)); } else { $order_date = ''; $order_datetime = ''; if ($email->email_type == 'manual') { $meta = maybe_unserialize($email_order->meta); $email_to = $meta['email_address']; $order = false; } else { $order = false; $user_id = $email_order->user_id; $wp_user = new WP_User($email_order->user_id); $email_to = $wp_user->user_email; $first_name = $wp_user->first_name; $last_name = $wp_user->last_name; $cname = $first_name . ' ' . $last_name; if (empty($first_name) && empty($last_name)) { $first_name = $wp_user->user_nicename; $cname = $wp_user->user_nicename; } // non-order related email. make sure user is not opted-out $opt_out = get_user_meta($email_order->user_id, 'wcfu_opted_out', true); $opt_out = apply_filters('fue_user_opt_out', $opt_out, $email_order->user_id); if ($opt_out) { // user opted out, delete this email_order $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}followup_email_orders WHERE `id` = %d", $email_order->id)); continue; } } } // check if the email address is on the excludes list $sql = $wpdb->prepare("SELECT COUNT(*) FROM `{$wpdb->prefix}followup_email_excludes` WHERE `email` = '%s'", $email_to); if ($wpdb->get_var($sql) > 0) { // delete and go to the next entry do_action('fue_email_excluded', $email_to, $email_order->id); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}followup_email_orders WHERE `id` = %d", $email_order->id)); continue; } if ($email->email_type == 'generic') { if ($order) { $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="' . self::create_email_url($email_order->id, $email->id, $user_id, $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 = ''; } } else { if (!empty($email_order->product_id)) { $item = sfn_get_product($email_order->product_id); $cats = get_the_terms($item->id, 'product_cat'); $categories = ''; if (is_array($cats) && !empty($cats)) { foreach ($cats as $cat) { $categories .= $cat->name . ', '; } $categories = rtrim($categories, ', '); } } else { } } // process variable replacements $tracking = $email->tracking_code; $codes = array(); if (!empty($tracking)) { parse_str($tracking, $codes); foreach ($codes as $key => $val) { $codes[$key] = urlencode($val); } } $store_url = home_url(); $store_name = get_bloginfo('name'); $page_id = woocommerce_get_page_id('followup_unsubscribe'); $unsubscribe = add_query_arg('wcfu', $email_to, get_permalink($page_id)); // convert urls $store_url = self::create_email_url($email_order->id, $email->id, $user_id, $email_to, $store_url); $unsubscribe = self::create_email_url($email_order->id, $email->id, $user_id, $email_to, $unsubscribe); if (!empty($codes)) { $store_url = add_query_arg($codes, $store_url); $unsubscribe = add_query_arg($codes, $unsubscribe); } $order_id = ''; if (0 != $email_order->order_id) { $order_id = apply_filters('woocommerce_order_number', $email_order->order_id, $order); } $subject = $email->subject; $message = $email->message; if ($email->email_type == 'generic') { /* Code by soumya */ /* Get order Total */ $order_t = get_post_meta($email_order->order_id, '_order_total', true); if (empty($order_t)) { $order_t = 0; } $order_t = '$' . $order_t; /** get servings details **/ $srOW = $wpdb->get_row("select * FROM wp_woocommerce_order_items WHERE order_id = " . $email_order->order_id); $mealOrder_serving = woocommerce_get_order_item_meta($srOW->order_item_id, 'Servings:', true); /* get delivery date */ $order_dd = get_post_meta($email_order->order_id, 'Delivery Date', true); if (empty($order_dd)) { $order_dd = ''; } $vars = array('{order_number}', '{order_date}', '{order_datetime}', '{store_url}', '{store_name}', '{customer_first_name}', '{customer_name}', '{customer_email}', '{item_names}', '{item_categories}', '{unsubscribe_url}', '{order_total}', '{order_delivery_date}', '{order_servings}'); $reps = array($order_id, $order_date, $order_datetime, $store_url, $store_name, $first_name, $first_name . ' ' . $last_name, $email_to, $item_list, $item_cats, $unsubscribe, $order_t, $order_dd, $mealOrder_serving); } elseif ($email->email_type == 'signup') { $vars = array('{store_url}', '{store_name}', '{customer_first_name}', '{customer_name}', '{customer_email}', '{unsubscribe_url}'); $reps = array($store_url, $store_name, $first_name, $cname, $email_to, $unsubscribe); } elseif ($email->email_type == 'customer') { if ($user_id > 0) { $customer = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}followup_customers WHERE user_id = %d", $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", $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_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_to)); $last_purchase = date(get_option('date_format'), strtotime($last_order_date)); } $vars = array('{order_number}', '{order_date}', '{order_datetime}', '{store_url}', '{store_name}', '{customer_first_name}', '{customer_name}', '{customer_email}', '{unsubscribe_url}', '{dollars_spent_order}', '{dollars_spent_total}', '{number_orders}', '{last_purchase_date}'); $reps = array($order_id, $order_date, $order_datetime, $store_url, $store_name, $first_name, $first_name . ' ' . $last_name, $email_to, $unsubscribe, $spent_order, $spent_total, $num_orders, $last_purchase); } elseif ($email->email_type == 'manual') { $meta = maybe_unserialize($email_order->meta); $store_url = home_url(); $store_name = get_bloginfo('name'); $page_id = woocommerce_get_page_id('followup_unsubscribe'); $unsubscribe = add_query_arg('wcfu', $email_to, get_permalink($page_id)); // convert urls $store_url = self::create_email_url($email_order->id, $email->id, $user_id, $email_to, $store_url); $unsubscribe = self::create_email_url($email_order->id, $email->id, $user_id, $email_to, $unsubscribe); if (!empty($codes)) { $store_url = add_query_arg($codes, $store_url); $unsubscribe = add_query_arg($codes, $unsubscribe); } $names = explode(' ', $meta['user_name']); $first_name = isset($names[0]) ? $names[0] : $meta['user_name']; $vars = array('{store_url}', '{store_name}', '{customer_first_name}', '{customer_name}', '{customer_email}', '{unsubscribe_url}'); $reps = array($store_url, $store_name, $first_name, $meta['user_name'], $email_to, $unsubscribe); $subject = $meta['subject']; $message = $meta['message']; } else { $item_url = self::create_email_url($email_order->id, $email->id, $user_id, $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); } /* Code by soumya */ /* Get order Total */ $order_t = get_post_meta($email_order->order_id, '_order_total', true); if (empty($order_t)) { $order_t = 0; } $order_t = '$' . $order_t; /** get servings details **/ $srOW = $wpdb->get_row("select * FROM wp_woocommerce_order_items WHERE order_id = " . $email_order->order_id); $mealOrder_serving = woocommerce_get_order_item_meta($srOW->order_item_id, 'Servings:', true); /* get delivery date */ $order_dd = get_post_meta($email_order->order_id, 'Delivery Date', true); if (empty($order_dd)) { $order_dd = ''; } $vars = array('{order_number}', '{order_date}', '{order_datetime}', '{store_url}', '{store_name}', '{customer_first_name}', '{customer_name}', '{customer_email}', '{item_name}', '{item_category}', '{unsubscribe_url}', '{order_total}', '{order_delivery_date}', '{order_servings}'); $reps = array($order_id, $order_date, $order_datetime, $store_url, $store_name, $first_name, $first_name . ' ' . $last_name, $email_to, '<a href="' . $item_url . '">' . get_the_title($item->id) . '</a>', $categories, $unsubscribe, $order_t, $order_dd, $mealOrder_serving); /* soumya code ended */ /* $vars = array('{order_number}', '{order_date}', '{order_datetime}', '{store_url}', '{store_name}', '{customer_first_name}', '{customer_name}', '{customer_email}', '{item_name}', '{item_category}', '{unsubscribe_url}'); $reps = array( $order_id, $order_date, $order_datetime, $store_url, $store_name, $first_name, $first_name .' '. $last_name, $email_to, '<a href="'. $item_url .'">'. get_the_title($item->id) .'</a>', $categories, $unsubscribe ); */ } //$email->message = self::url_to_links( $email->message, $email_order->id, $email->id, $user_id, $email_to ); if ($email_order->order_id > 0 && $email->email_type == 'reminder') { // count the total emails and the number of sent emails $total_emails = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}followup_email_orders WHERE order_id = %d AND email_id = %d", $email_order->order_id, $email->id)); $sent_emails = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}followup_email_orders WHERE order_id = %d AND email_id = %d AND is_sent = 1", $email_order->order_id, $email->id)); if ($total_emails == 1) { $messages = self::str_search('{first_email}', '{/first_email}', $message); if (empty($messages)) { continue; } $message = $messages[0]; } elseif ($total_emails == 2) { if ($sent_emails == 0) { $messages = self::str_search('{first_email}', '{/first_email}', $message); if (empty($messages)) { continue; } $message = $messages[0]; } else { $messages = self::str_search('{final_email}', '{/final_email}', $message); if (empty($messages)) { continue; } $message = $messages[0]; } } else { if ($sent_emails == 0) { $messages = self::str_search('{first_email}', '{/first_email}', $message); if (empty($messages)) { continue; } $message = $messages[0]; } elseif ($sent_emails == $total_emails - 1) { $messages = self::str_search('{final_email}', '{/final_email}', $message); if (empty($messages)) { continue; } $message = $messages[0]; } else { $messages = self::str_search('{quantity_email}', '{/quantity_email}', $message); if (empty($messages)) { continue; } $message = $messages[0]; } } } $subject = apply_filters('fue_email_subject', $subject, $email, $email_order); $message = apply_filters('fue_email_message', $message, $email, $email_order); $subject = strip_tags(str_replace($vars, $reps, $subject)); $message = str_replace($vars, $reps, $message); // hook to variable replacement $subject = apply_filters('fue_send_email_subject', $subject, $email_order); $message = apply_filters('fue_send_email_message', $message, $email_order); // look for custom fields $message = preg_replace_callback('|\\{cf ([0-9]+) ([^}]*)\\}|', 'fue_add_custom_fields', $message); // look for post id $message = preg_replace_callback('|\\{post_id=([^}]+)\\}|', 'fue_add_post', $message); // look for links $replacer = new FUE_Link_Replacement($email_order->id, $email->id, $user_id, $email_to); $message = preg_replace_callback('|\\{link url=([^}]+)\\}|', array($replacer, 'replace'), $message); // look for store_url with path $sfnFollowUpEmails->link_meta = array('email_order_id' => $email_order->id, 'email_id' => $email->id, 'user_id' => $user_id, 'user_email' => $email_to, 'codes' => $codes); $message = preg_replace_callback('|\\{store_url=([^}]+)\\}|', 'FUE::add_store_url', $message); do_action('fue_before_email_send', $subject, $message, $email_order); // send the email $disable_wrap = get_option('fue_disable_wrapping', 0); $mailer = $woocommerce->mailer(); if (!$disable_wrap) { $message = $mailer->wrap_message($subject, $message); } $mailer->send($email_to, $subject, $message); $oid = $order ? $email_order->order_id : 0; if ($email->email_type == 'manual') { $email_trigger = __('Manual Email', 'wc_followup_emails'); } else { if ($email->interval_type == 'date') { $email_trigger = sprintf(__('Send on %s'), $email->send_date . ' ' . $email->send_date_hour . ':' . $email->send_date_minute); } elseif ($email->interval_type == 'signup') { $email_trigger = sprintf(__('%d %s after user signs up', 'wc_followup_emails'), $email->interval_num, $email->interval_duration); } else { $email_trigger = sprintf(__('%d %s %s'), $email->interval_num, $email->interval_duration, SFN_FollowUpEmails::get_trigger_name($email->interval_type)); } } $email_trigger = apply_filters('fue_interval_str', $email_trigger, $email); do_action('fue_after_email_sent', $subject, $message, $email_order); do_action('fue_email_sent_details', $email_order, $email_order->user_id, $email, $email_to, $cname, $email_trigger); // increment usage count $wpdb->query($wpdb->prepare("UPDATE `{$wpdb->prefix}followup_emails` SET `usage_count` = `usage_count` + 1 WHERE `id` = %d", $email->id)); // update the email order $now = date('Y-m-d H:i:s'); $wpdb->query($wpdb->prepare("UPDATE `{$wpdb->prefix}followup_email_orders` SET `is_sent` = 1, `date_sent` = %s, `email_trigger` = %s WHERE `id` = %d", $now, $email_trigger, $email_order->id)); do_action('fue_email_order_sent', $email_order->id); } }
function settings() { global $wpdb, $woocommerce; $tab = isset($_GET['tab']) ? $_GET['tab'] : 'list'; if ($tab == 'list') { $generics = $this->get_emails('generic'); $categories = $this->get_emails('category'); $products = $this->get_emails('product'); $signups = $this->get_emails('signup'); fue_settings_header($tab); include FUE_TEMPLATES_DIR . '/emails_list.php'; fue_settings_footer(); } elseif ($tab == 'new') { // load the categories $categories = get_terms('product_cat', array('order_by' => 'name', 'order' => 'ASC')); fue_settings_header($tab); include FUE_TEMPLATES_DIR . '/new_email.php'; fue_settings_footer(); } elseif ($tab == 'edit') { $id = $_GET['id']; $email = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}followup_emails` WHERE `id` = %d", $id)); $product = false; if ($email->product_id != 0) { $product = sfn_get_product($email->product_id); } // load the categories $categories = get_terms('product_cat'); if (!$email) { wp_die("The requested data could not be found!"); } fue_settings_header($tab); include FUE_TEMPLATES_DIR . '/edit_email.php'; fue_settings_footer(); } elseif ($tab == 'delete') { $id = $_GET['id']; // delete $wpdb->query($wpdb->prepare("DELETE FROM `{$wpdb->prefix}followup_email_orders` WHERE `email_id` = %d", $id)); $wpdb->query($wpdb->prepare("DELETE FROM `{$wpdb->prefix}followup_emails` WHERE `id` = %d", $id)); wp_redirect('admin.php?page=wc-followup-emails&tab=list&deleted=true'); exit; } elseif ($tab == 'settings') { $pages = get_pages(); $page = woocommerce_get_page_id('followup_unsubscribe'); $emails = get_option('fue_daily_emails'); fue_settings_header($tab); include FUE_TEMPLATES_DIR . '/settings.php'; fue_settings_footer(); } else { // allow add-ons to add tabs do_action('fue_settings_tab_controller', $tab); fue_settings_footer(); } }