/** * Queue emails after an RMA's status changes * * @param int $request_id * @param string $status */ public function status_updated($request_id, $status) { global $wpdb; $order_id = get_post_meta($request_id, '_order_id', true); $triggers = array('warranty_status'); $emails = fue_get_emails('any', FUE_Email::STATUS_ACTIVE, array('meta_query' => array(array('key' => '_interval_type', 'value' => 'warranty_status')))); foreach ($emails as $email) { $interval = (int) $email->interval_num; $insert = array('send_on' => $email->get_send_timestamp(), 'email_id' => $email->id, 'user_id' => 0, 'order_id' => $order_id, 'is_cart' => 0); if (!is_wp_error(FUE_Sending_Scheduler::queue_email($insert, $email))) { // Tell FUE that an email order has been created // to stop it from sending storewide emails if (!defined('FUE_ORDER_CREATED')) { define('FUE_ORDER_CREATED', true); } } } FUE_Addon_Woocommerce::create_email_orders($triggers, $order_id); }
/** * Action fired after points have been increased * * @param int $user_id * @param int $points * @param string $event_type * @param array $data * @param int $order_id */ public function after_points_increased($user_id, $points, $event_type, $data = null, $order_id = 0) { $emails = fue_get_emails('points_and_rewards', FUE_Email::STATUS_ACTIVE, array('meta_query' => array(array('key' => '_interval_type', 'value' => array('points_earned', 'points_greater_than'), 'compare' => 'IN')))); foreach ($emails as $email) { if ($email->interval_type == 'points_greater_than') { $meta = maybe_unserialize($email->meta); if ($points < $meta['points_greater_than']) { continue; } } $insert = array('send_on' => $email->get_send_timestamp(), 'email_id' => $email->id, 'user_id' => $user_id, 'order_id' => $order_id, 'is_cart' => 0); $email_order_id = FUE_Sending_Scheduler::queue_email($insert, $email); if (!is_wp_error($email_order_id)) { $data = array('user_id' => $user_id, 'points' => $points, 'event_type' => $event_type); update_option('fue_email_order_' . $email_order_id, $data); // Tell FUE that an email order has been created // to stop it from sending storewide emails if (!defined('FUE_ORDER_CREATED')) { define('FUE_ORDER_CREATED', true); } } } }
<?php /** * Update FUE Data to 7.1 * * Merge storewide and product emails together */ if (!defined('ABSPATH')) { exit; // Exit if accessed directly } global $wpdb; $product_emails = fue_get_emails('product', array(FUE_Email::STATUS_ARCHIVED, FUE_Email::STATUS_ACTIVE, FUE_Email::STATUS_INACTIVE)); foreach ($product_emails as $email) { $args = array('id' => $email->id, 'type' => 'storewide'); fue_update_email($args); }
/** * Set expiration reminder after the subscription gets activated * * @param int $user_id * @param string $subs_key */ public function set_expiration_reminder($user_id, $subs_key) { $parts = explode('_', $subs_key); $order_id = $parts[0]; $product_id = $parts[1]; $order = WC_FUE_Compatibility::wc_get_order($order_id); $queued = array(); if (!WC_Subscriptions_Order::order_contains_subscription($order)) { return; } $expiry_date = WC_Subscriptions_Manager::get_subscription_expiration_date($subs_key, $user_id); if (!$expiry_date) { return; } // convert to local time $expiry_timestamp = get_date_from_gmt($expiry_date, 'U'); if (current_time('timestamp', true) > $expiry_timestamp) { return; } // look for renewal emails $emails = fue_get_emails('any', FUE_Email::STATUS_ACTIVE, array('meta_query' => array(array('key' => '_interval_type', 'value' => 'subs_before_expire')))); if (count($emails) > 0) { foreach ($emails as $email) { // product_id filter if (!empty($email->product_id) && $product_id != $email->product_id) { continue; } // look for a possible duplicate item in the queue $dupes = Follow_Up_Emails::instance()->scheduler->get_items(array('email_id' => $email->id, 'is_sent' => 0, 'order_id' => $order_id, 'user_id' => $user_id)); if (count($dupes) > 0) { // there already is an unsent queue item for the exact same order continue; } // add this email to the queue $interval = (int) $email->interval_num; $add = FUE_Sending_Scheduler::get_time_to_add($interval, $email->interval_duration); $send_on = $expiry_timestamp - $add; $insert = array('user_id' => $user_id, 'send_on' => $send_on, 'email_id' => $email->id, 'product_id' => 0, 'order_id' => $order_id); if ($subs_key) { $insert['meta']['subs_key'] = $subs_key; } if (!is_wp_error(FUE_Sending_Scheduler::queue_email($insert, $email))) { $queued[] = $insert; } } } if (count($queued) > 0) { $this->add_order_notes_to_queued_emails($queued); } }
/** * @param string $status Filter emails by status (e.g. FUE_Email::STATUS_ACTIVE * @param array $args * @return array */ protected function get_cart_emails($status = '', $args = array()) { $query = array('meta_query' => array(array('key' => '_interval_type', 'value' => 'cart'))); if (isset($args['product_id'])) { $query['meta_query'][] = array('key' => '_product_id', 'value' => absint($args['product_id'])); } if (isset($args['category_id'])) { $query['meta_query'][] = array('key' => '_category_id', 'value' => $args['category_id'], 'compare' => 'IN'); } if (isset($args['always_send'])) { $query['meta_query'][] = array('key' => '_always_send', 'value' => $args['always_send']); } //$args = array_merge( $query, $args ); return fue_get_emails('any', $status, $query); }
if (!empty($_GET['campaign'])) { include FUE_TEMPLATES_DIR . '/email-list/campaign-list.php'; } else { ?> <form action="admin-post.php" method="post" id="update_priorities"> <div class="subsubsub_section"> <?php include FUE_TEMPLATES_DIR . '/email-list/menu.php'; ?> <?php foreach ($types as $key => $type) { $emails = fue_get_emails($type->id, array('fue-active', 'fue-inactive')); $archived_emails = fue_get_emails($type->id, 'fue-archived'); $bcc = isset($bccs[$type->id]) ? $bccs[$type->id] : ''; $from = isset($from_addresses[$type->id]) ? $from_addresses[$type->id] : ''; if (!empty($type->list_template) && is_readable($type->list_template)) { include $type->list_template; } else { include FUE_TEMPLATES_DIR . '/email-list/simple-list.php'; } } do_action('fue_email_types_section'); ?> </div> <p class="submit"> <input type="hidden" name="action" value="fue_followup_save_list" /> <input type="submit" name="update_priorities" value="<?php
/** * Queue emails after an order is marked as completed * @param int $order_id */ public function set_reminders($order_id) { global $woocommerce, $wpdb; // load reminder emails $emails = fue_get_emails('wootickets', FUE_Email::STATUS_ACTIVE, array('meta_query' => array(array('key' => '_interval_type', 'value' => array('before_tribe_event_starts', 'after_tribe_event_ends'), 'compare' => 'IN')))); $tickets = array(); if (empty($emails)) { return; } $has_tickets = get_post_meta($order_id, '_tribe_has_tickets', true); $order = WC_FUE_Compatibility::wc_get_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_Sending_Scheduler::get_time_to_add($interval, $email->interval_duration); foreach ($tickets as $ticket_id) { // if this email is for a specific ticket, make sure the IDs match if (!empty($email->product_id) && $email->product_id != $ticket_id) { continue; } // check for category matching if (!empty($email->category_id)) { $ticket_terms = get_the_terms($ticket_id, 'product_cat'); $product_categories = array(); if ($ticket_terms && !is_wp_error($ticket_terms)) { foreach ($ticket_terms as $ticket_term) { $product_categories[$ticket_term->term_id] = $ticket_term->name; } } if (!array_key_exists($email->category_id, $product_categories)) { continue; } } $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 $email_meta = maybe_unserialize($email->meta); if (isset($email_meta['tribe_limit'], $email_meta['tribe_limit_days']) && !empty($email_meta['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_Sending_Scheduler::queue_email($insert, $email); } } }
/** * Send emails that matches the provided triggers to the queue * @param int $booking_id * @param array $triggers */ private function create_email_order($booking_id, $triggers = array()) { /** * @var $booking WC_Booking * @var $order WC_Order */ $booking = get_wc_booking($booking_id); $last_status = get_post_meta($booking_id, '_last_status', true); $order = WC_FUE_Compatibility::wc_get_order($booking->order_id); $emails = fue_get_emails('wc_bookings', FUE_Email::STATUS_ACTIVE, array('meta_query' => array(array('key' => '_interval_type', 'value' => $triggers, 'compare' => 'IN')))); foreach ($emails as $email) { if (!empty($email->meta['bookings_last_status']) && $email->meta['bookings_last_status'] != $last_status) { continue; } if ($this->is_category_excluded($booking, $email)) { continue; } // A booking can have no order linked to it if ($order) { $customer = fue_get_customer_from_order($order); if (Follow_Up_Emails::instance()->fue_wc->wc_scheduler->exclude_customer_based_on_purchase_history($customer, $email)) { continue; } } if ($email->interval_type == 'before_booking_event') { $start = strtotime(get_post_meta($booking_id, '_booking_start', true)); $time = FUE_Sending_Scheduler::get_time_to_add($email->interval_num, $email->interval_duration); $send_on = $start - $time; } elseif ($email->interval_type == 'after_booking_event') { $start = strtotime(get_post_meta($booking_id, '_booking_end', true)); $time = FUE_Sending_Scheduler::get_time_to_add($email->interval_num, $email->interval_duration); $send_on = $start + $time; } else { $send_on = $email->get_send_timestamp(); } $insert = array('send_on' => $send_on, 'email_id' => $email->id, 'product_id' => $booking->product_id, 'order_id' => $booking->order_id, 'meta' => array('booking_id' => $booking_id)); if ($order) { $user_id = WC_FUE_Compatibility::get_order_user_id($order); if ($user_id) { $user = new WP_User($user_id); $insert['user_id'] = $user_id; $insert['user_email'] = $user->user_email; } } // Remove the nonce to avoid infinite loop because doing a // remove_action on WC_Bookings_Details_Meta_Box doesnt work unset($_POST['wc_bookings_details_meta_box_nonce']); if (!is_wp_error(FUE_Sending_Scheduler::queue_email($insert, $email))) { // Tell FUE that an email order has been created // to stop it from sending storewide emails if (!defined('FUE_ORDER_CREATED')) { define('FUE_ORDER_CREATED', true); } } } }
<?php /** * Update Data to 7.5 * Look for queue items for subscription emails without subscription keys in the meta */ if (!defined('ABSPATH')) { exit; // Exit if accessed directly } global $wpdb; if (class_exists('WC_Subscriptions_Manager')) { $email_ids = fue_get_emails('subscription', '', array('fields' => 'ids')); if (count($email_ids)) { $item_ids = $wpdb->get_results("SELECT id FROM {$wpdb->prefix}followup_email_orders WHERE email_id IN (" . implode(',', $email_ids) . ")"); foreach ($item_ids as $item_id) { $item = new FUE_Sending_Queue_Item($item_id->id); if (empty($item->meta['subs_key']) && WC_Subscriptions_Order::order_contains_subscription($item->order_id)) { $subs_key = WC_Subscriptions_Manager::get_subscription_key($item->order_id); $item->meta['subs_key'] = $subs_key; $item->save(); } } } }
/** * Check if a specific answer has been submitted * * @param array $args * @param array $data */ public function check_for_answer($args, $data) { global $wpdb; if ($args['type'] != 'sensei_user_answer') { return; } $question_id = $args['post_id']; $emails = fue_get_emails('sensei', FUE_Email::STATUS_ACTIVE, array('meta_query' => array(array('key' => '_interval_type', 'value' => 'specific_answer')))); foreach ($emails as $email) { $meta = maybe_unserialize($email->meta); if (is_array($meta)) { $email_question_id = isset($meta['sensei_question_id']) ? $meta['sensei_question_id'] : ''; $email_answer = isset($meta['sensei_answer']) ? $meta['sensei_answer'] : ''; // The answer to check for is required if (empty($email_answer)) { continue; } // Question IDs must match if ($email_question_id != $question_id) { continue; } $posted_answer = maybe_unserialize(base64_decode($args['data'])); // answers do not match if (is_array($posted_answer)) { $posted_answer = current($posted_answer); } if ($email_answer != $posted_answer) { continue; } $values = array('user_id' => $args['user_id'], 'meta' => array('question_id' => $question_id, 'answer' => $posted_answer)); FUE_Sending_Scheduler::queue_email($values, $email); } } }
<?php $slug = $_GET['campaign']; $campaign = get_term_by('slug', $slug, 'follow_up_email_campaign'); $emails = fue_get_emails('any', '', array('follow_up_email_campaign' => $slug)); ?> <div id="message" class="updated"> <p><?php printf(__('You are viewing emails under the <b>%s</b> campaign. <a href="admin.php?page=followup-emails">Remove filter</a>', 'follow_up_emails'), $campaign->name); ?> </p> </div> <h3><?php printf(__('%s Emails', 'follow_up_emails'), $campaign->name); ?> </h3> <table class="wp-list-table widefat fixed posts fue <?php echo $slug; ?> -table"> <thead> <tr> <th style="" class="manage-column column-cb check-column" scope="col"><label for="cb-select-all-1" class="screen-reader-text"><?php _e('Select All', 'follow_up_emails'); ?> </label><input type="checkbox" id="cb-select-all-1"></th> <th scope="col" id="title" class="manage-column column-title" width="200" style=""><?php _e('Name', 'follow_up_emails');