public function replace($matches) { if (empty($matches)) { return ''; } $url = $matches[1]; return FUE_Sending_Mailer::create_email_url($this->email_order_id, $this->email_id, $this->user_id, $this->user_email, $url); }
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 = WC_FUE_Compatibility::wc_get_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); $billing_address = $order->get_formatted_billing_address(); $shipping_address = $order->get_formatted_shipping_address(); $item = WC_Subscriptions_Order::get_item_by_product_id($order); $item_id = WC_Subscriptions_Order::get_items_product_id($item); $renewal = self::calculate_next_payment_timestamp($order, $item_id); $subs_key = WC_Subscriptions_Manager::get_subscription_key($email_order->order_id, $item_id); $renew_date = date(get_option('date_format'), $renewal); $end_date = WC_Subscriptions_Manager::get_subscription_expiration_date($subs_key, '', 'timestamp'); if ($end_date == 0) { $end_date = __('Until Cancelled', 'follow_up_emails'); } else { $end_date = date(get_option('date_format'), $end_date); } // calc days to renew $now = current_time('timestamp'); $diff = $renewal - $now; $days_to_renew = 0; if ($diff > 0) { $days_to_renew = floor($diff / 86400); } $item_url = FUE_Sending_Mailer::create_email_url($email_order->id, $email_row->id, $email_data['user_id'], $email_data['email_to'], get_permalink($item_id)); $categories = ''; if ($item_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, ', '); } } $reps = array_merge($reps, array($order_id, $order_date, $order_datetime, $billing_address, $shipping_address, $email_data['username'], $email_data['first_name'], $email_data['first_name'] . ' ' . $email_data['last_name'], $email_data['email_to'], $renew_date, $end_date, $days_to_renew, '<a href="' . $item_url . '">' . get_the_title($item_id) . '</a>', $categories)); } return $reps; }
/** * Send a summary of emails sent within a defined time period */ public static function send_summary() { // send the email $subject = __('Follow-up emails summary', 'follow_up_emails'); $recipient = self::get_summary_recipient_emails(); $body = self::get_summary_email_html(); FUE_Sending_Mailer::mail($recipient, $subject, $body); update_option('fue_last_summary', current_time('timestamp')); update_option('fue_next_summary', current_time('timestamp') + 86400); }
/** * Get replacement data for product and reminder emails * * @param array $replacements * @param array $email_data * @param object $queue_item * @param FUE_Email $email * * @return array */ private function get_replacement_data_for_product($replacements, $email_data, $queue_item, $email) { $categories = ''; $item_name = ''; $item_price = ''; if (!empty($queue_item->product_id)) { $item = WC_FUE_Compatibility::wc_get_product($queue_item->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_Sending_Mailer::create_email_url($queue_item->id, $queue_item->id, $email_data['user_id'], $email_data['email_to'], get_permalink($queue_item->product_id)); $item_name = '<a href="' . $item_url . '">' . get_the_title($queue_item->product_id) . '</a>'; $order = WC_FUE_Compatibility::wc_get_order($queue_item->order_id); if ($order instanceof WC_Order) { foreach ($order->get_items() as $order_item) { if ($order_item['product_id'] == $queue_item->product_id) { $replacements['item_quantity'] = $order_item['qty']; break; } } } $item_price = strip_tags($item->get_price_html()); } $replacements['item_name'] = $item_name; $replacements['item_price'] = $item_price; return $replacements; }