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);
 }
コード例 #2
0
 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);
         $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);
         $renew_date = date(get_option('date_format'), $renewal);
         // 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::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, $email_data['first_name'], $email_data['first_name'] . ' ' . $email_data['last_name'], $email_data['email_to'], $renew_date, $days_to_renew, '<a href="' . $item_url . '">' . get_the_title($item_id) . '</a>', $categories));
     }
     return $reps;
 }
コード例 #3
0
 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;
 }