Exemplo n.º 1
0
?>
" class="button" />
                    </td>
                </tr>
            </tbody>
        </table>
        <p class="submit">
            <input type="hidden" name="action" value="sfn_followup_new" />
            <input type="submit" id="save" name="save" class="hideable btn_save button-primary" value="<?php 
_e('Save Follow-Up Email', 'wc_followup_emails');
?>
" />
        </p>
    </form>
    <script type="text/javascript">
    var interval_types = <?php 
echo json_encode(SFN_FollowUpEmails::get_trigger_types());
?>
;
    var email_intervals = <?php 
echo json_encode(SFN_FollowUpEmails::get_email_type_triggers());
?>
;

    jQuery(document).ready(function() {
        <?php 
do_action('fue_new_email_form_script');
?>
    });
    </script>
Exemplo n.º 2
0
 public function interval_string($string, $email)
 {
     if ($email->interval_type == 'points_greater_than') {
         $meta = maybe_unserialize($email->meta);
         $string = sprintf(__('%d %s %s %d'), $email->interval_num, SFN_FollowUpEmails::get_duration($email->interval_duration), SFN_FollowUpEmails::get_trigger_name($email->interval_type), $meta['points_greater_than']);
     }
     return $string;
 }
Exemplo n.º 3
0
        ?>
</a></span>
                                |
                                <span class="trash"><a onclick="return confirm('Really delete this entry?');" href="admin.php?page=wc-followup-emails&tab=delete&id=<?php 
        echo $email->id;
        ?>
"><?php 
        _e('Delete', 'wc_followup_emails');
        ?>
</a></span>
                            </div>
                        </td>
                        <td>
                            <?php 
        if ($email->interval_duration != 'date') {
            printf(__('%d %s after user signs up'), $email->interval_num, SFN_FollowUpEmails::get_duration($email->interval_duration));
        } else {
            printf(__('Send on %s'), $email->send_date);
        }
        ?>
                        </td>
                        <td>
                        <?php 
        echo $email->usage_count;
        ?>
                        </td>
                        <?php 
        do_action('fue_table_signups_body');
        ?>
                    </tr>
                    <?php 
Exemplo n.º 4
0
        </table>
        <p class="submit">
            <input type="hidden" name="action" value="sfn_followup_edit" />
            <input type="hidden" name="id" id="id" value="<?php 
echo $id;
?>
" />
            <input type="submit" name="save" id="save" value="<?php 
_e('Update Follow-Up Email', 'wc_followup_emails');
?>
" class="button-primary" />
        </p>
    </form>
    <script type="text/javascript">
    var interval_types = <?php 
echo json_encode(SFN_FollowUpEmails::get_trigger_types());
?>
;
    jQuery(document).ready(function() {
        var sfn_checked = false;
        jQuery("select.ajax_chosen_select_products_and_variations").change(function() {
            // remove the first option to limit to only 1 product per email
            if (jQuery(this).find("option:selected").length > 1) {
                while (jQuery(this).find("option:selected").length > 1) {
                    jQuery(jQuery(this).find("option:selected")[0]).remove();
                }
                
                jQuery(this).trigger("liszt:updated");
            }
            jQuery("#use_custom_field").change();
        });
Exemplo n.º 5
0
 /**
  * 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);
     }
 }
Exemplo n.º 6
0
 static function get_trigger_types($email_type = '')
 {
     $order_statuses = (array) get_terms('shop_order_status', array('hide_empty' => 0, 'orderby' => 'id'));
     $triggers = self::$triggers;
     $order_triggers = array();
     if (!isset($order_statuses['errors'])) {
         foreach ($order_statuses as $status) {
             $triggers[$status->slug] = sprintf(__('after Order Status: %s', 'wc_followup_emails'), $status->name);
             $order_triggers[] = $status->slug;
             //self::$email_type_triggers['normal'][]  = $status->slug;
             //self::$email_type_triggers['generic'][] = $status->slug;
         }
     }
     self::$email_type_triggers['normal'] = array_unique(array_merge(self::$email_type_triggers['normal'], $order_triggers));
     self::$email_type_triggers['generic'] = array_unique(array_merge(self::$email_type_triggers['generic'], $order_triggers));
     $triggers = apply_filters('fue_trigger_types', $triggers, $email_type);
     self::$triggers = $triggers;
     return self::$triggers;
 }
Exemplo n.º 7
0
 /** 
  * 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);
     }
 }
Exemplo n.º 8
0
 public function interval_string($string, $email)
 {
     if ($email->interval_type == 'before_tribe_event_starts' || $email->interval_type == 'after_tribe_event_ends') {
         $string = sprintf(__('%d %s %s'), $email->interval_num, SFN_FollowUpEmails::get_duration($email->interval_duration), SFN_FollowUpEmails::get_trigger_name($email->interval_type));
     }
     return $string;
 }
Exemplo n.º 9
0
        ?>
</a></span>
                                |
                                <span class="trash"><a onclick="return confirm('Really delete this entry?');" href="admin.php?page=wc-followup-emails&tab=delete&id=<?php 
        echo $email->id;
        ?>
"><?php 
        _e('Delete', 'wc_followup_emails');
        ?>
</a></span>
                            </div>
                        </td>
                        <td>
                        <?php 
        if ($email->interval_duration != 'date') {
            printf(__('%d %s after %s'), $email->interval_num, SFN_FollowUpEmails::get_duration($email->interval_duration), SFN_FollowUpEmails::get_trigger_name($email->interval_type));
        } else {
            printf(__('Send on %s'), $email->send_date);
        }
        ?>


                        </td>
                        <td>
                            <?php 
        echo $email->usage_count;
        ?>

                        </td>
                        <td>
                            <?php 
 static function get_trigger_types()
 {
     $order_statuses = (array) get_terms('shop_order_status', array('hide_empty' => 0, 'orderby' => 'id'));
     $triggers = self::$triggers;
     if (!isset($order_statuses['errors'])) {
         foreach ($order_statuses as $status) {
             $triggers[$status->slug] = sprintf(__('Order Status: %s', 'wc_followup_emails'), $status->name);
         }
     }
     self::$triggers = $triggers;
     return apply_filters('fue_trigger_types', self::$triggers);
 }
Exemplo n.º 11
0
    public function email_list_table()
    {
        global $wpdb;
        $emails = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}followup_emails WHERE `email_type` = 'subscription' ORDER BY `priority` ASC, `name` ASC");
        ?>

        <div class="section" id="subscription_mails">
            <h3><?php 
        _e('Subscription Emails', 'wc_followup_emails');
        ?>
</h3>

            <table class="wp-list-table widefat fixed posts subscription-table">
                <thead>
                    <tr>
                        <th scope="col" id="subscription_priority" class="manage-column column-type" style="width:50px;"><?php 
        _e('Priority', 'wc_followup_emails');
        ?>
</th>
                        <th scope="col" id="subscription_type" class="manage-column column-type" style=""><?php 
        _e('Name', 'wc_followup_emails');
        ?>
</th>
                        <th scope="col" id="subscription_interval" class="manage-column column-amount" style=""><?php 
        _e('Interval', 'wc_followup_emails');
        ?>
</th>
                        <th scope="col" id="subscription_usage_count" class="manage-column column-usage_count" style=""><?php 
        _e('Used', 'wc_followup_emails');
        ?>
</th>
                        <?php 
        do_action('fue_table_customer_head');
        ?>

                    </tr>
                </thead>
                <tbody id="the_list">
                    <?php 
        if (empty($emails)) {
            ?>

                    <tr scope="row">
                        <th colspan="4"><?php 
            _e('No emails available', 'wc_followup_emails');
            ?>
</th>
                    </tr>
                    <?php 
        } else {
            $p = 0;
            foreach ($emails as $email) {
                $p++;
                ?>

                    <tr scope="row">
                        <td style="text-align: center; vertical-align:middle;"><span class="priority"><?php 
                echo $p;
                ?>
</span></td>
                        <td class="post-title column-title">
                            <input type="hidden" name="generic_order[]" value="<?php 
                echo $email->id;
                ?>
" />
                            <strong><a class="row-title" href="admin.php?page=wc-followup-emails&tab=edit&id=<?php 
                echo $email->id;
                ?>
"><?php 
                echo stripslashes($email->name);
                ?>
</a></strong>
                            <div class="row-actions">
                                <span class="edit"><a href="admin.php?page=wc-followup-emails&tab=edit&id=<?php 
                echo $email->id;
                ?>
"><?php 
                _e('Edit', 'wc_followup_emails');
                ?>
</a></span>
                                |
                                <span class="trash"><a onclick="return confirm('Really delete this entry?');" href="admin.php?page=wc-followup-emails&tab=delete&id=<?php 
                echo $email->id;
                ?>
"><?php 
                _e('Delete', 'wc_followup_emails');
                ?>
</a></span>
                            </div>
                        </td>
                        <td>
                            <?php 
                $interval_str = sprintf(__('%d %s %s'), $email->interval_num, SFN_FollowUpEmails::get_duration($email->interval_duration), SFN_FollowUpEmails::get_trigger_name($email->interval_type));
                echo apply_filters('fue_interval_str', $interval_str, $email);
                ?>

                        </td>
                        <td>
                        <?php 
                echo $email->usage_count;
                ?>

                        </td>
                        <?php 
                do_action('fue_table_customer_body');
                ?>

                    </tr>
                    <?php 
            }
            ?>

                    <?php 
        }
        ?>

                </tbody>
            </table>
            <div class="fue_table_footer">
                <div class="order_message"></div>
            </div>
        </div>
        <?php 
    }