public static function send_mail_by_mail_sending_option($each_cart, $emails, $find_user)
 {
     global $wpdb;
     $abandancart_table_name = $wpdb->prefix . 'rac_abandoncart';
     $tablecheckproduct = fp_rac_extract_cart_details($each_cart);
     $sent_mail_templates = '';
     if (empty($each_cart->mail_template_id)) {
         // IF EMPTY IT IS NOT SENT FOR ANY SINGLE TEMPLATE
         if ($emails->sending_type == 'hours') {
             $duration = $emails->sending_duration * 3600;
         } else {
             if ($emails->sending_type == 'minutes') {
                 $duration = $emails->sending_duration * 60;
             } else {
                 if ($emails->sending_type == 'days') {
                     $duration = $emails->sending_duration * 86400;
                 }
             }
         }
         //duration is finished
         $cut_off_time = $each_cart->cart_abandon_time + $duration;
         $current_time = current_time('timestamp');
         if ($current_time > $cut_off_time) {
             @($cart_url = WC_Cart::get_cart_url());
             if ($find_user == 'member') {
                 $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id), $cart_url));
                 $user = get_userdata($each_cart->user_id);
                 $to = $user->user_email;
                 $firstname = $user->user_firstname;
                 $lastname = $user->user_lastname;
             } elseif ($find_user == 'guest1') {
                 $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'guest' => 'yes'), $cart_url));
                 @($order_object = maybe_unserialize($each_cart->cart_details));
                 $to = $order_object->billing_email;
                 $subject = fp_get_wpml_text('rac_template_' . $emails->id . '_subject', $each_cart->wpml_lang, $emails->subject);
                 $firstname = $order_object->billing_first_name;
                 $lastname = $order_object->billing_last_name;
             } elseif ($find_user == 'guest2') {
                 $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'guest' => 'yes', 'checkout' => 'yes'), $cart_url));
                 @($order_object = maybe_unserialize($each_cart->cart_details));
                 $to = $order_object['visitor_mail'];
                 $subject = fp_get_wpml_text('rac_template_' . $emails->id . '_subject', $each_cart->wpml_lang, $emails->subject);
                 $firstname = $order_object['first_name'];
                 $lastname = $order_object['last_name'];
             } elseif ($find_user == 'old_order') {
                 $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'old_order' => 'yes'), $cart_url));
                 @($cart_array = maybe_unserialize($each_cart->cart_details));
                 $id = $cart_array->id;
                 $order_object = new WC_Order($id);
                 $to = $order_object->billing_email;
                 $subject = fp_get_wpml_text('rac_template_' . $emails->id . '_subject', $each_cart->wpml_lang, $emails->subject);
                 $firstname = $order_object->billing_first_name;
                 $lastname = $order_object->billing_last_name;
             }
             if (get_option('rac_cart_link_options') == '1') {
                 $url_to_click = '<a style="color:#' . get_option("rac_email_link_color") . '"  href="' . $url_to_click . '">' . fp_get_wpml_text('rac_template_' . $emails->id . '_anchor_text', $each_cart->wpml_lang, $emails->anchor_text) . '</a>';
             } elseif (get_option('rac_cart_link_options') == '2') {
                 $url_to_click = $url_to_click;
             } else {
                 $cart_Text = fp_get_wpml_text('rac_template_' . $emails->id . '_anchor_text', $each_cart->wpml_lang, $emails->anchor_text);
                 $url_to_click = RecoverAbandonCart::rac_cart_link_button_mode($url_to_click, $cart_Text);
             }
             $subject = fp_get_wpml_text('rac_template_' . $emails->id . '_subject', $each_cart->wpml_lang, $emails->subject);
             $message = fp_get_wpml_text('rac_template_' . $emails->id . '_message', $each_cart->wpml_lang, $emails->message);
             $subject = RecoverAbandonCart::shortcode_in_subject($firstname, $lastname, $subject);
             $message = str_replace('{rac.cartlink}', $url_to_click, $message);
             $message = str_replace('{rac.firstname}', $firstname, $message);
             $message = str_replace('{rac.lastname}', $lastname, $message);
             $message = str_replace('{rac.Productinfo}', $tablecheckproduct, $message);
             if (strpos($message, "{rac.coupon}")) {
                 $coupon_code = FPRacCoupon::rac_create_coupon($to, $each_cart->cart_abandon_time);
                 $message = str_replace('{rac.coupon}', $coupon_code, $message);
                 //replacing shortcode with coupon code
                 update_option('abandon_time_of' . $each_cart->id, $coupon_code);
             }
             $message = RecoverAbandonCart::rac_unsubscription_shortcode($to, $message);
             add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
             $message = do_shortcode($message);
             //shortcode feature
             $html_template = $emails->mail;
             // mail send plain or html
             $logo = '<table><tr><td align="center" valign="top"><p style="margin-top:0;"><img src="' . esc_url($emails->link) . '" /></p></td></tr></table>';
             // mail uploaded
             $woo_temp_msg = self::email_woocommerce_html($html_template, $subject, $message, $logo);
             // mail send plain or html
             $headers = "MIME-Version: 1.0\r\n";
             $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
             if ($emails->sender_opt == 'local') {
                 $headers .= self::rac_formatted_from_address_local($emails->from_name, $emails->from_email);
                 $headers .= "Reply-To: " . $emails->from_name . "<" . $emails->from_email . ">\r\n";
             } else {
                 $headers .= self::rac_formatted_from_address_woocommerce();
                 $headers .= "Reply-To: " . get_option('woocommerce_email_from_name') . " <" . get_option('woocommerce_email_from_address') . ">\r\n";
             }
             if ($each_cart->sending_status == 'SEND') {
                 if ('wp_mail' == get_option('rac_trouble_mail')) {
                     if (self::rac_send_wp_mail($to, $subject, $woo_temp_msg, $headers)) {
                         $sent_mail_templates[] = $emails->id;
                         $store_template_id = maybe_serialize($sent_mail_templates);
                         $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                         $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                         $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $each_cart->id, "template_used" => $emails->id));
                         FPRacCounter::rac_do_mail_count();
                     }
                 } else {
                     if (self::rac_send_mail($to, $subject, $woo_temp_msg, $headers)) {
                         $sent_mail_templates[] = $emails->id;
                         $store_template_id = maybe_serialize($sent_mail_templates);
                         $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                         $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                         $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $each_cart->id, "template_used" => $emails->id));
                         FPRacCounter::rac_do_mail_count();
                     }
                 }
             }
         }
     } elseif (!empty($each_cart->mail_template_id)) {
         $sent_mail_templates = maybe_unserialize($each_cart->mail_template_id);
         if (!in_array($emails->id, (array) $sent_mail_templates)) {
             if ($emails->sending_type == 'hours') {
                 $duration = $emails->sending_duration * 3600;
             } else {
                 if ($emails->sending_type == 'minutes') {
                     $duration = $emails->sending_duration * 60;
                 } else {
                     if ($emails->sending_type == 'days') {
                         $duration = $emails->sending_duration * 86400;
                     }
                 }
             }
             //duration is finished
             $cut_off_time = $each_cart->cart_abandon_time + $duration;
             $current_time = current_time('timestamp');
             if ($current_time > $cut_off_time) {
                 @($cart_url = WC_Cart::get_cart_url());
                 if ($find_user == 'member') {
                     $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id), $cart_url));
                     $user = get_userdata($each_cart->user_id);
                     $to = $user->user_email;
                     $firstname = $user->user_firstname;
                     $lastname = $user->user_lastname;
                 } elseif ($find_user == 'guest1') {
                     $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'guest' => 'yes'), $cart_url));
                     @($order_object = maybe_unserialize($each_cart->cart_details));
                     $to = $order_object->billing_email;
                     $subject = fp_get_wpml_text('rac_template_' . $emails->id . '_subject', $each_cart->wpml_lang, $emails->subject);
                     $firstname = $order_object->billing_first_name;
                     $lastname = $order_object->billing_last_name;
                 } elseif ($find_user == 'guest2') {
                     $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'guest' => 'yes', 'checkout' => 'yes'), $cart_url));
                     @($order_object = maybe_unserialize($each_cart->cart_details));
                     $to = $order_object['visitor_mail'];
                     $subject = fp_get_wpml_text('rac_template_' . $emails->id . '_subject', $each_cart->wpml_lang, $emails->subject);
                     $firstname = $order_object['first_name'];
                     $lastname = $order_object['last_name'];
                 } elseif ($find_user == 'old_order') {
                     $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'old_order' => 'yes'), $cart_url));
                     @($cart_array = maybe_unserialize($each_cart->cart_details));
                     $id = $cart_array->id;
                     $order_object = new WC_Order($id);
                     $to = $order_object->billing_email;
                     $subject = fp_get_wpml_text('rac_template_' . $emails->id . '_subject', $each_cart->wpml_lang, $emails->subject);
                     $firstname = $order_object->billing_first_name;
                     $lastname = $order_object->billing_last_name;
                 }
                 if (get_option('rac_cart_link_options') == '1') {
                     $url_to_click = '<a style="color:#' . get_option("rac_email_link_color") . '"  href="' . $url_to_click . '">' . fp_get_wpml_text('rac_template_' . $emails->id . '_anchor_text', $each_cart->wpml_lang, $emails->anchor_text) . '</a>';
                 } elseif (get_option('rac_cart_link_options') == '2') {
                     $url_to_click = $url_to_click;
                 } else {
                     $cart_Text = fp_get_wpml_text('rac_template_' . $emails->id . '_anchor_text', $each_cart->wpml_lang, $emails->anchor_text);
                     $url_to_click = RecoverAbandonCart::rac_cart_link_button_mode($url_to_click, $cart_Text);
                 }
                 $subject = fp_get_wpml_text('rac_template_' . $emails->id . '_subject', $each_cart->wpml_lang, $emails->subject);
                 $message = fp_get_wpml_text('rac_template_' . $emails->id . '_message', $each_cart->wpml_lang, $emails->message);
                 $subject = RecoverAbandonCart::shortcode_in_subject($firstname, $lastname, $subject);
                 $message = str_replace('{rac.cartlink}', $url_to_click, $message);
                 $message = str_replace('{rac.firstname}', $firstname, $message);
                 $message = str_replace('{rac.lastname}', $lastname, $message);
                 $message = str_replace('{rac.Productinfo}', $tablecheckproduct, $message);
                 if (strpos($message, "{rac.coupon}")) {
                     $coupon_code = FPRacCoupon::rac_create_coupon($to, $each_cart->cart_abandon_time);
                     $message = str_replace('{rac.coupon}', $coupon_code, $message);
                     //replacing shortcode with coupon code
                     update_option('abandon_time_of' . $each_cart->id, $coupon_code);
                 }
                 $message = RecoverAbandonCart::rac_unsubscription_shortcode($to, $message);
                 add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                 $message = do_shortcode($message);
                 //shortcode feature
                 $html_template = $emails->mail;
                 // mail send plain or html
                 $logo = '<table><tr><td align="center" valign="top"><p style="margin-top:0;"><img src="' . esc_url($emails->link) . '" /></p></td></tr></table>';
                 // mail uploaded
                 $woo_temp_msg = self::email_woocommerce_html($html_template, $subject, $message, $logo);
                 // mail send plain or html
                 $headers = "MIME-Version: 1.0\r\n";
                 $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
                 if ($emails->sender_opt == 'local') {
                     $headers .= self::rac_formatted_from_address_local($emails->from_name, $emails->from_email);
                     $headers .= "Reply-To: " . $emails->from_name . " <" . $emails->from_email . ">\r\n";
                 } else {
                     $headers .= self::rac_formatted_from_address_woocommerce();
                     $headers .= "Reply-To: " . get_option('woocommerce_email_from_name') . "<" . get_option('woocommerce_email_from_address') . ">\r\n";
                 }
                 if ($each_cart->sending_status == 'SEND') {
                     //condition to check start/stop mail sending
                     if ('wp_mail' == get_option('rac_trouble_mail')) {
                         if (self::rac_send_wp_mail($to, $subject, $woo_temp_msg, $headers)) {
                             $sent_mail_templates[] = $emails->id;
                             $store_template_id = maybe_serialize($sent_mail_templates);
                             $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                             $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                             $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $each_cart->id, "template_used" => $emails->id));
                             FPRacCounter::rac_do_mail_count();
                         }
                     } else {
                         if (self::rac_send_mail($to, $subject, $woo_temp_msg, $headers)) {
                             $sent_mail_templates[] = $emails->id;
                             $store_template_id = maybe_serialize($sent_mail_templates);
                             $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                             $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                             $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $each_cart->id, "template_used" => $emails->id));
                             FPRacCounter::rac_do_mail_count();
                         }
                     }
                 }
             }
         }
     }
 }
    public static function rac_send_manual_mail()
    {
        global $wpdb, $woocommerce, $to;
        $table_name = $wpdb->prefix . 'rac_abandoncart';
        // $emailtemplate_table_name = $wpdb->prefix . 'rac_templates_email';
        $abandancart_table_name = $wpdb->prefix . 'rac_abandoncart';
        $sender_option_post = stripslashes($_POST['rac_sender_option']);
        $mail_template_post = stripslashes($_POST['rac_template_mail']);
        // mail plain or html
        $mail_logo_added = stripslashes($_POST['rac_logo_mail']);
        // mail logo uploaded
        $from_name_post = stripslashes($_POST['rac_from_name']);
        $from_email_post = stripslashes($_POST['rac_from_email']);
        $message_post = stripslashes($_POST['rac_message']);
        $subject_post = stripslashes($_POST['rac_mail_subject']);
        $anchor_text_post = stripslashes($_POST['rac_anchor_text']);
        $mail_row_ids = stripslashes($_POST['rac_mail_row_ids']);
        $row_id_array = explode(',', $mail_row_ids);
        $mail_template_id_post = isset($_POST['template_id']) ? $_POST['template_id'] : '';
        $table_name_email = $wpdb->prefix . 'rac_templates_email';
        $logo = '<table><tr><td align="center" valign="top"><p style="margin-top:0;"><img src="' . esc_url($mail_logo_added) . '" /></p></td></tr></table>';
        // mail uploaded
        ?>

        <style type="text/css">
            table {
                border-collapse: separate;
                border-spacing: 0;
                color: #4a4a4d;
                font: 14px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
            }
            th,
            td {
                padding: 10px 15px;
                vertical-align: middle;
            }
            thead {
                background: #395870;
                background: linear-gradient(#49708f, #293f50);
                color: #fff;
                font-size: 11px;
                text-transform: uppercase;
            }
            th:first-child {
                border-top-left-radius: 5px;
                text-align: left;
            }
            th:last-child {
                border-top-right-radius: 5px;
            }
            tbody tr:nth-child(even) {
                background: #f0f0f2;
            }
            td {
                border-bottom: 1px solid #cecfd5;
                border-right: 1px solid #cecfd5;
            }
            td:first-child {
                border-left: 1px solid #cecfd5;
            }
            .book-title {
                color: #395870;
                display: block;
            }
            .text-offset {
                color: #7c7c80;
                font-size: 12px;
            }
            .item-stock,
            .item-qty {
                text-align: center;
            }
            .item-price {
                text-align: right;
            }
            .item-multiple {
                display: block;
            }
            tfoot {
                text-align: right;
            }
            tfoot tr:last-child {
                background: #f0f0f2;
                color: #395870;
                font-weight: bold;
            }
            tfoot tr:last-child td:first-child {
                border-bottom-left-radius: 5px;
            }
            tfoot tr:last-child td:last-child {
                border-bottom-right-radius: 5px;
            }

        </style>
        <?php 
        //$mail_temp_row = $wpdb->get_results("SELECT * FROM $table_name_email WHERE id=$template_id_post", OBJECT);
        $headers = "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
        if ($sender_option_post == 'local') {
            $headers .= FPRacCron::rac_formatted_from_address_local($from_name_post, $from_email_post);
            $headers .= "Reply-To: " . $from_name_post . " <" . $from_email_post . ">\r\n";
        } else {
            $headers .= FPRacCron::rac_formatted_from_address_woocommerce();
            $headers .= "Reply-To: " . get_option('woocommerce_email_from_name') . " <" . get_option('woocommerce_email_from_address') . ">\r\n";
        }
        foreach ($row_id_array as $row_id) {
            $cart_row = $wpdb->get_results("SELECT * FROM {$table_name} WHERE id={$row_id}", OBJECT);
            //echo $cart_row[0]->user_id;
            //For Member
            $cart_array = maybe_unserialize($cart_row[0]->cart_details);
            $tablecheckproduct = fp_rac_extract_cart_details($cart_row[0]);
            if ($cart_row[0]->user_id != '0' && $cart_row[0]->user_id != 'old_order') {
                //echo 'member';
                $sent_mail_templates = maybe_unserialize($cart_row[0]->mail_template_id);
                if (!is_array($sent_mail_templates)) {
                    $sent_mail_templates = array();
                    // to avoid mail sent/not sent problem for serialization on store
                }
                $current_time = current_time('timestamp');
                @($cart_url = WC_Cart::get_cart_url());
                $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $cart_row[0]->id, 'email_template' => $mail_template_id_post), $cart_url));
                if (get_option('rac_cart_link_options') == '1') {
                    $url_to_click = '<a style="color:#' . get_option("rac_email_link_color") . '"  href="' . $url_to_click . '">' . fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_anchor_text', $cart_row[0]->wpml_lang, $anchor_text_post) . '</a>';
                } elseif (get_option('rac_cart_link_options') == '2') {
                    $url_to_click = $url_to_click;
                } else {
                    $cart_text = fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_anchor_text', $cart_row[0]->wpml_lang, $anchor_text_post);
                    $url_to_click = self::rac_cart_link_button_mode($url_to_click, $cart_text);
                }
                //$url_to_click = '<a href="' . $url_to_click . '">' . fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_anchor_text', $cart_row[0]->wpml_lang, $anchor_text_post) . '</a>';
                $user = get_userdata($cart_row[0]->user_id);
                $to = $user->user_email;
                $firstname = $user->user_firstname;
                $lastname = $user->user_lastname;
                // $logo = '<p style="float:left; margin-top:0"><img src="' . esc_url( $mail_logo_added ) . '" /></p>'; // mail uploaded
                $subject = fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_subject', $cart_row[0]->wpml_lang, $subject_post);
                $subject = self::shortcode_in_subject($firstname, $lastname, $subject);
                $message = fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_message', $cart_row[0]->wpml_lang, $message_post);
                $message = str_replace('{rac.cartlink}', $url_to_click, $message);
                $message = str_replace('{rac.firstname}', $firstname, $message);
                $message = str_replace('{rac.lastname}', $lastname, $message);
                $message = str_replace('{rac.Productinfo}', $tablecheckproduct, $message);
                if (strpos($message, "{rac.coupon}")) {
                    $coupon_code = FPRacCoupon::rac_create_coupon($user->user_email, $cart_row[0]->cart_abandon_time);
                    update_option('abandon_time_of' . $cart_row[0]->id, $coupon_code);
                    $message = str_replace('{rac.coupon}', $coupon_code, $message);
                    //replacing shortcode with coupon code
                }
                $message = RecoverAbandonCart::rac_unsubscription_shortcode($to, $message);
                add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                $message = do_shortcode($message);
                //shortcode feature
                $logo = '<table><tr><td align="center" valign="top"><p style="margin-top:0;"><img src="' . esc_url($mail_logo_added) . '" /></p></td></tr></table>';
                // mail uploaded
                // mail send plain or html
                $woo_temp_msg = self::email_woocommerce_html($mail_template_post, $subject, $message, $logo);
                // mail send plain or html
                if ('wp_mail' == get_option('rac_trouble_mail')) {
                    if (FPRacCron::rac_send_wp_mail($to, $subject, $woo_temp_msg, $headers)) {
                        //wp_mail($to, $subject, $message);
                        $sent_mail_templates[] = $mail_template_id_post;
                        $store_template_id = maybe_serialize($sent_mail_templates);
                        $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $cart_row[0]->id));
                        //add to mail log
                        $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                        $template_used = $mail_template_id_post . '- Manual';
                        $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $cart_row[0]->id, "template_used" => $template_used));
                        FPRacCounter::rac_do_mail_count();
                    }
                } else {
                    if (FPRacCron::rac_send_mail($to, $subject, $woo_temp_msg, $headers)) {
                        //wp_mail($to, $subject, $message);
                        $sent_mail_templates[] = $mail_template_id_post;
                        $store_template_id = maybe_serialize($sent_mail_templates);
                        $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $cart_row[0]->id));
                        //add to mail log
                        $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                        $template_used = $mail_template_id_post . '- Manual';
                        $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $cart_row[0]->id, "template_used" => $template_used));
                        FPRacCounter::rac_do_mail_count();
                    }
                }
            }
            //End Member
            //FOR Guest at place order
            if ($cart_row[0]->user_id === '0' && is_null($cart_row[0]->ip_address)) {
                // echo 'guest';
                $sent_mail_templates = maybe_unserialize($cart_row[0]->mail_template_id);
                if (!is_array($sent_mail_templates)) {
                    $sent_mail_templates = array();
                    // to avoid mail sent/not sent problem for serialization on store
                }
                $current_time = current_time('timestamp');
                @($cart_url = WC_Cart::get_cart_url());
                $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $cart_row[0]->id, 'email_template' => $mail_template_id_post, 'guest' => 'yes'), $cart_url));
                //$url_to_click = '<a href="' . $url_to_click . '">' . fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_anchor_text', $cart_row[0]->wpml_lang, $anchor_text_post) . '</a>';
                if (get_option('rac_cart_link_options') == '1') {
                    $url_to_click = '<a style="color:#' . get_option("rac_email_link_color") . '" href="' . $url_to_click . '">' . fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_anchor_text', $cart_row[0]->wpml_lang, $anchor_text_post) . '</a>';
                } elseif (get_option('rac_cart_link_options') == '2') {
                    $url_to_click = $url_to_click;
                } else {
                    $cart_text = fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_anchor_text', $cart_row[0]->wpml_lang, $anchor_text_post);
                    $url_to_click = self::rac_cart_link_button_mode($url_to_click, $cart_text);
                }
                //  $user = get_userdata($each_cart->user_id); NOT APPLICABLE
                $order_object = maybe_unserialize($cart_row[0]->cart_details);
                $to = $order_object->billing_email;
                $firstname = $order_object->billing_first_name;
                $lastname = $order_object->billing_last_name;
                $subject = self::shortcode_in_subject($firstname, $lastname, $subject_post);
                $message = str_replace('{rac.cartlink}', $url_to_click, $message_post);
                $message = str_replace('{rac.firstname}', $firstname, $message);
                $message = str_replace('{rac.lastname}', $lastname, $message);
                $message = str_replace('{rac.Productinfo}', $tablecheckproduct, $message);
                if (strpos($message, "{rac.coupon}")) {
                    $coupon_code = FPRacCoupon::rac_create_coupon($order_object->billing_email, $cart_row[0]->cart_abandon_time);
                    update_option('abandon_time_of' . $cart_row[0]->id, $coupon_code);
                    $message = str_replace('{rac.coupon}', $coupon_code, $message);
                    //replacing shortcode with coupon code
                }
                $message = RecoverAbandonCart::rac_unsubscription_shortcode($to, $message);
                $message = do_shortcode($message);
                //shortcode feature
                add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                $logo = '<table><tr><td align="center" valign="top"><p style="margin-top:0;"><img src="' . esc_url($mail_logo_added) . '" /></p></td></tr></table>';
                // mail uploaded
                // mail send plain or html
                $woo_temp_msg = self::email_woocommerce_html($mail_template_post, $subject, $message, $logo);
                // mail send plain or html
                if ('wp_mail' == get_option('rac_trouble_mail')) {
                    if (FPRacCron::rac_send_wp_mail($to, $subject, $woo_temp_msg, $headers)) {
                        // wp_mail($to, $subject, $message);
                        $sent_mail_templates[] = $mail_template_id_post;
                        $store_template_id = maybe_serialize($sent_mail_templates);
                        $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $cart_row[0]->id));
                        //add to mail log
                        $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                        $template_used = $mail_template_id_post . '- Manual';
                        $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $cart_row[0]->id, "template_used" => $template_used));
                        FPRacCounter::rac_do_mail_count();
                    }
                } else {
                    if (FPRacCron::rac_send_mail($to, $subject, $woo_temp_msg, $headers)) {
                        // wp_mail($to, $subject, $message);
                        $sent_mail_templates[] = $mail_template_id_post;
                        $store_template_id = maybe_serialize($store_template_id);
                        $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $cart_row[0]->id));
                        //add to mail log
                        $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                        $template_used = $mail_template_id_post . '- Manual';
                        $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $cart_row[0]->id, "template_used" => $template_used));
                        FPRacCounter::rac_do_mail_count();
                    }
                }
            }
            //END Guest
            //GUEST Checkout
            if ($cart_row[0]->user_id == '0' && !is_null($cart_row[0]->ip_address)) {
                // echo 'checkout';
                $sent_mail_templates = maybe_unserialize($cart_row[0]->mail_template_id);
                if (!is_array($sent_mail_templates)) {
                    $sent_mail_templates = array();
                    // to avoid mail sent/not sent problem for serialization on store
                }
                $current_time = current_time('timestamp');
                @($cart_url = WC_Cart::get_cart_url());
                $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $cart_row[0]->id, 'email_template' => $mail_template_id_post, 'guest' => 'yes', 'checkout' => 'yes'), $cart_url));
                if (get_option('rac_cart_link_options') == '1') {
                    $url_to_click = '<a style="color:#' . get_option("rac_email_link_color") . '"  href="' . $url_to_click . '">' . fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_anchor_text', $cart_row[0]->wpml_lang, $anchor_text_post) . '</a>';
                } elseif (get_option('rac_cart_link_options') == '2') {
                    $url_to_click = $url_to_click;
                } else {
                    $cart_text = fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_anchor_text', $cart_row[0]->wpml_lang, $anchor_text_post);
                    $url_to_click = self::rac_cart_link_button_mode($url_to_click, $cart_text);
                }
                //  $user = get_userdata($each_cart->user_id); NOT APPLICABLE
                $order_object = maybe_unserialize($cart_row[0]->cart_details);
                $to = $order_object['visitor_mail'];
                $firstname = $order_object['first_name'];
                $lastname = $order_object['last_name'];
                $message = str_replace('{rac.cartlink}', $url_to_click, $message_post);
                $subject = self::shortcode_in_subject($firstname, $lastname, $subject_post);
                $message = str_replace('{rac.firstname}', $firstname, $message);
                $message = str_replace('{rac.lastname}', $lastname, $message);
                $message = str_replace('{rac.Productinfo}', $tablecheckproduct, $message);
                if (strpos($message, "{rac.coupon}")) {
                    $coupon_code = FPRacCoupon::rac_create_coupon($order_object['visitor_mail'], $cart_row[0]->cart_abandon_time);
                    update_option('abandon_time_of' . $cart_row[0]->id, $coupon_code);
                    $message = str_replace('{rac.coupon}', $coupon_code, $message);
                    //replacing shortcode with coupon code
                }
                $message = do_shortcode($message);
                //shortcode feature
                $logo = '<table><tr><td align="center" valign="top"><p style="margin-top:0;"><img src="' . esc_url($mail_logo_added) . '" /></p></td></tr></table>';
                // mail uploaded
                // mail send plain or html
                $woo_temp_msg = self::email_woocommerce_html($mail_template_post, $subject, $message, $logo);
                // mail send plain or html
                if ('wp_mail' == get_option('rac_trouble_mail')) {
                    if (FPRacCron::rac_send_wp_mail($to, $subject, $woo_temp_msg, $headers)) {
                        // wp_mail($to, $subject, $message);
                        $sent_mail_templates[] = $mail_template_id_post;
                        $store_template_id = maybe_serialize($sent_mail_templates);
                        $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $cart_row[0]->id));
                        //add to mail log
                        $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                        $template_used = $mail_template_id_post . '- Manual';
                        $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $cart_row[0]->id, "template_used" => $template_used));
                        FPRacCounter::rac_do_mail_count();
                    }
                } else {
                    if (FPRacCron::rac_send_mail($to, $subject, $woo_temp_msg, $headers)) {
                        // wp_mail($to, $subject, $message);
                        $sent_mail_templates[] = $mail_template_id_post;
                        $store_template_id = maybe_serialize($sent_mail_templates);
                        $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $cart_row[0]->id));
                        //add to mail log
                        $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                        $template_used = $mail_template_id_post . '- Manual';
                        $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $cart_row[0]->id, "template_used" => $template_used));
                        FPRacCounter::rac_do_mail_count();
                    }
                }
            }
            //END Checkout
            //Order Updated
            if ($cart_row[0]->user_id == 'old_order' && is_null($cart_row[0]->ip_address)) {
                // echo 'order';
                $sent_mail_templates = maybe_unserialize($each_cart->mail_template_id);
                $current_time = current_time('timestamp');
                @($cart_url = WC_Cart::get_cart_url());
                $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $cart_row[0]->id, 'email_template' => $mail_template_id_post, 'old_order' => 'yes'), $cart_url));
                //$url_to_click = '<a href="' . $url_to_click . '">' . fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_anchor_text', $cart_row[0]->wpml_lang, $anchor_text_post) . '</a>';
                if (get_option('rac_cart_link_options') == '1') {
                    $url_to_click = '<a style="color:#' . get_option("rac_email_link_color") . '"  href="' . $url_to_click . '">' . fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_anchor_text', $cart_row[0]->wpml_lang, $anchor_text_post) . '</a>';
                } elseif (get_option('rac_cart_link_options') == '2') {
                    $url_to_click = $url_to_click;
                } else {
                    $cart_text = fp_get_wpml_text('rac_template_' . $mail_template_id_post . '_anchor_text', $cart_row[0]->wpml_lang, $anchor_text_post);
                    $url_to_click = self::rac_cart_link_button_mode($url_to_click, $cart_text);
                }
                //  $user = get_userdata($each_cart->user_id); NOT APPLICABLE
                $order_object = maybe_unserialize($cart_row[0]->cart_details);
                $to = $order_object->billing_email;
                $firstname = $order_object->billing_first_name;
                $lastname = $order_object->billing_last_name;
                $message = str_replace('{rac.cartlink}', $url_to_click, $message_post);
                $subject = self::shortcode_in_subject($firstname, $lastname, $subject_post);
                $message = str_replace('{rac.firstname}', $firstname, $message);
                $message = str_replace('{rac.lastname}', $lastname, $message);
                $message = str_replace('{rac.Productinfo}', $tablecheckproduct, $message);
                if (strpos($message, "{rac.coupon}")) {
                    $coupon_code = FPRacCoupon::rac_create_coupon($order_object->billing_email, $cart_row[0]->cart_abandon_time);
                    update_option('abandon_time_of' . $cart_row[0]->id, $coupon_code);
                    $message = str_replace('{rac.coupon}', $coupon_code, $message);
                    //replacing shortcode with coupon code
                }
                $message = do_shortcode($message);
                //shortcode feature
                $logo = '<table><tr><td align="center" valign="top"><p style="margin-top:0;"><img src="' . esc_url($mail_logo_added) . '" /></p></td></tr></table>';
                // mail uploaded
                // mail send plain or html
                $woo_temp_msg = self::email_woocommerce_html($mail_template_post, $subject, $message, $logo);
                // mail send plain or html
                if ('wp_mail' == get_option('rac_trouble_mail')) {
                    if (FPRacCron::rac_send_wp_mail($to, $subject, $woo_temp_msg, $headers)) {
                        // wp_mail($to, $subject, $message);
                        $sent_mail_templates[] = $mail_template_id_post;
                        $store_template_id = maybe_serialize($sent_mail_templates);
                        $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $cart_row[0]->id));
                        //add to mail log
                        $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                        $template_used = $mail_template_id_post . '- Manual';
                        $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $cart_row[0]->id, "template_used" => $template_used));
                        FPRacCounter::rac_do_mail_count();
                    }
                } else {
                    if (FPRacCron::rac_send_mail($to, $subject, $woo_temp_msg, $headers)) {
                        // wp_mail($to, $subject, $message);
                        $sent_mail_templates[] = $mail_template_id_post;
                        $store_template_id = maybe_serialize($sent_mail_templates);
                        $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $cart_row[0]->id));
                        //add to mail log
                        $table_name_logs = $wpdb->prefix . 'rac_email_logs';
                        $template_used = $mail_template_id_post . '- Manual';
                        $wpdb->insert($table_name_logs, array("email_id" => $to, "date_time" => $current_time, "rac_cart_id" => $cart_row[0]->id, "template_used" => $template_used));
                        FPRacCounter::rac_do_mail_count();
                    }
                }
            }
            // var_dump($cart_row[0]->user_id);
        }
        exit;
    }