The WooCommerce cart class stores cart data and active coupons as well as handling customer sessions and some cart related urls. The cart class also has a price calculation function which calls upon other classes to calculate totals.
Author: WooThemes
 /**
  * Callback function that gets called when a customer cancels the payment directly
  */
 public static function onCancel()
 {
     self::debug(__CLASS__ . ': OnCancel - URL: http' . ($_SERVER['SERVER_PORT'] == 443 ? "s://" : "://") . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
     $order = self::$wc_api->getOrderFromApiUrl();
     $order->add_order_note(__('PayPro - Customer cancelled payment. Redirected him back to his cart.'));
     self::debug(__CLASS__ . ': OnCancel - Payment cancelled by customer for order: ' . $order->id . '. Redirecting back to cart.');
     wp_safe_redirect(WC_Cart::get_cart_url());
     exit;
 }
 /**
  * Sets a cookie when the cart has something in it. Can be used by hosts to prevent caching if set.
  *
  * @access public
  * @param mixed $set
  * @return void
  */
 public function cart_has_contents_cookie($set)
 {
     if (!headers_sent()) {
         if ($set) {
             setcookie("woocommerce_items_in_cart", "1", 0, COOKIEPATH, COOKIE_DOMAIN, false);
             setcookie("woocommerce_cart_hash", md5(json_encode($this->cart->get_cart())), 0, COOKIEPATH, COOKIE_DOMAIN, false);
         } else {
             setcookie("woocommerce_items_in_cart", "0", time() - 3600, COOKIEPATH, COOKIE_DOMAIN, false);
             setcookie("woocommerce_cart_hash", "0", time() - 3600, COOKIEPATH, COOKIE_DOMAIN, false);
         }
     }
 }
 /**
  * Add order/subscription fee line items to the cart when a renewal order, initial order or resubscribe is in the cart.
  *
  * @param WC_Cart $cart
  * @since 2.0.13
  */
 public function maybe_add_fees($cart)
 {
     if ($cart_item = $this->cart_contains()) {
         $order = $this->get_order($cart_item);
         if ($order instanceof WC_Order) {
             foreach ($order->get_fees() as $fee) {
                 $cart->add_fee($fee['name'], $fee['line_total'], abs($fee['line_tax']) > 0, $fee['tax_class']);
             }
         }
     }
 }
 function display_order_shipping_addresses($order)
 {
     global $woocommerce;
     $order_id = $order->id;
     $addresses = get_post_meta($order_id, '_shipping_addresses', true);
     $methods = get_post_meta($order_id, '_shipping_methods', true);
     $packages = get_post_meta($order_id, '_wcms_packages', true);
     $items = $order->get_items();
     $available_methods = $woocommerce->shipping->load_shipping_methods();
     //if (empty($addresses)) return;
     if (!$packages || count($packages) == 1) {
         return;
     }
     // load the address fields
     $this->load_cart_files();
     $checkout = new WC_Checkout();
     $cart = new WC_Cart();
     $shipFields = $woocommerce->countries->get_address_fields($woocommerce->countries->get_base_country(), 'shipping_');
     echo '<p><strong>' . __('This order ships to multiple addresses.', 'wc_shipping_multiple_address') . '</strong></p>';
     echo '<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">';
     echo '<thead><tr>';
     echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Product', 'woocommerce') . '</th>';
     echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Qty', 'woocommerce') . '</th>';
     echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('', 'woocommerce') . '</th>';
     echo '</thead><tbody>';
     foreach ($packages as $x => $package) {
         $products = $package['contents'];
         $method = $methods[$x]['label'];
         foreach ($available_methods as $ship_method) {
             if ($ship_method->id == $method) {
                 $method = $ship_method->get_title();
                 break;
             }
         }
         $address = isset($package['full_address']) && !empty($package['full_address']) ? $woocommerce->countries->get_formatted_address($package['full_address']) : '';
         foreach ($products as $i => $product) {
             echo '<tr>';
             echo '<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">' . get_the_title($product['data']->id) . '<br />' . $cart->get_item_data($product, true) . '</td>';
             echo '<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $product['quantity'] . '</td>';
             echo '<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">' . $address . '<br/><em>( ' . $method . ' )</em></td>';
             echo '</tr>';
         }
     }
     echo '</table>';
 }
 /**
  * Stores shipping info on the subscription
  *
  * @param WC_Subscription $subscription instance of a subscriptions object
  * @param WC_Cart $cart A cart with recurring items in it
  */
 public static function add_shipping($subscription, $cart)
 {
     // We need to make sure we only get recurring shipping packages
     WC_Subscriptions_Cart::set_calculation_type('recurring_total');
     foreach ($cart->get_shipping_packages() as $package_index => $base_package) {
         $package = WC_Subscriptions_Cart::get_calculated_shipping_for_package($base_package);
         $recurring_shipping_package_key = WC_Subscriptions_Cart::get_recurring_shipping_package_key($cart->recurring_cart_key, $package_index);
         $shipping_method_id = isset(WC()->checkout()->shipping_methods[$package_index]) ? WC()->checkout()->shipping_methods[$package_index] : '';
         if (isset(WC()->checkout()->shipping_methods[$recurring_shipping_package_key])) {
             $shipping_method_id = WC()->checkout()->shipping_methods[$recurring_shipping_package_key];
             $package_key = $recurring_shipping_package_key;
         } else {
             $package_key = $package_index;
         }
         if (isset($package['rates'][$shipping_method_id])) {
             $item_id = $subscription->add_shipping($package['rates'][$shipping_method_id]);
             if (!$item_id) {
                 throw new Exception(__('Error: Unable to create subscription. Please try again.', 'woocommerce-subscriptions'));
             }
             // Allows plugins to add order item meta to shipping
             do_action('woocommerce_add_shipping_order_item', $subscription->id, $item_id, $package_key);
             do_action('woocommerce_subscriptions_add_recurring_shipping_order_item', $subscription->id, $item_id, $package_key);
         }
     }
     WC_Subscriptions_Cart::set_calculation_type('none');
 }
        _e('Product', 'woocommerce-pip');
        ?>
</th>
                        <th scope="col" style="text-align:left; width: 15%;"><?php 
        _e('Quantity', 'woocommerce-pip');
        ?>
</th>
                        <th scope="col" style="text-align:left; width: 20%;"><?php 
        _e('Total Weight', 'woocommerce-pip');
        ?>
</th>
                    </tr>
                    </thead>
                        <tbody>
                        <?php 
        $cart = new WC_Cart();
        foreach ($package['contents'] as $item_key => $item) {
            $attributes = $cart->get_item_data($item, true);
            // get the product; if this variation or product has been deleted, this will return null...
            $_product = $order->get_product_from_item($item);
            $sku = $variation = '';
            if ($_product) {
                $sku = $_product->get_sku();
            }
            if (!empty($attributes)) {
                $variation = '<small style="display: block; margin: 5px 0 10px 10px;">' . str_replace("\n", "<br/>", $attributes) . '</small>';
            }
            ?>
                            <tr>
                            <td style="text-align:left; padding: 3px;"><?php 
            echo $sku;
    /**
     * Prepare recurring amounts, taxes etc for subscription items
     * 
     * @access public
     * @param int $order_id
     * @return void
     */
    public function new_order($order_id)
    {
        global $woocommerce;

        // Iterate over real cart and work with subscription products (if any)
        foreach ($woocommerce->cart->cart_contents as $cart_item_key => $cart_item) {

            $id = !empty($cart_item['variation_id']) ? $cart_item['variation_id'] : $cart_item['product_id'];

            if (Subscriptio_Subscription_Product::is_subscription($id)) {

                $product = new WC_Product($id);

                // Store all required renewal order fields here
                $renewal_order = array(
                    'taxes'     => array(),
                    'shipping'  => array(),
                );

                // Create fake cart to mimic renewal order
                $renewal_cart = new WC_Cart();

                // Add product to cart
                $renewal_cart->add_to_cart(
                    $cart_item['product_id'],
                    $cart_item['quantity'],
                    (isset($cart_item['variation_id']) ? $cart_item['variation_id'] : ''),
                    (isset($cart_item['variation']) ? $cart_item['variation'] : '')
                );

                // Get fake cart item key
                $renewal_cart_item_keys = array_keys($renewal_cart->cart_contents);
                $renewal_cart_item_key = array_shift($renewal_cart_item_keys);

                // Set renewal price
                $renewal_cart->cart_contents[$renewal_cart_item_key]['data']->price = Subscriptio_Subscription_Product::get_recurring_price($id);

                // Add shipping
                if ($product->needs_shipping() && $renewal_cart->needs_shipping()) {

                    // Get instance of checkout object to retrieve shipping options
                    $wc_checkout = WC_Checkout::instance();

                    // Iterate over shipping packages
                    foreach ($woocommerce->shipping->get_packages() as $package_key => $package) {

                        // Check if this rate was selected
                        if (isset($package['rates'][$wc_checkout->shipping_methods[$package_key]])) {

                            // Check if it contains current subscription
                            if (isset($package['contents'][$cart_item_key])) {

                                // Save shipping details for further calculation
                                $shipping_details = array(
                                    'shipping_method'   => $wc_checkout->shipping_methods[$package_key],
                                    'destination'       => $package['destination'],
                                );

                                // Save shipping address
                                $renewal_order['shipping_address'] = array(
                                    // First three lines may need to be changed to make this compatible with shipping extensions that allow multiple shipping addresses
                                    '_shipping_first_name'  => $wc_checkout->posted['ship_to_different_address'] ? $wc_checkout->posted['shipping_first_name'] : $wc_checkout->posted['billing_first_name'],
                                    '_shipping_last_name'   => $wc_checkout->posted['ship_to_different_address'] ? $wc_checkout->posted['shipping_last_name'] : $wc_checkout->posted['billing_last_name'],
                                    '_shipping_company'     => $wc_checkout->posted['ship_to_different_address'] ? $wc_checkout->posted['shipping_company'] : $wc_checkout->posted['billing_company'],
                                    '_shipping_address_1'   => $shipping_details['destination']['address'],
                                    '_shipping_address_2'   => $shipping_details['destination']['address_2'],
                                    '_shipping_city'        => $shipping_details['destination']['city'],
                                    '_shipping_state'       => $shipping_details['destination']['state'],
                                    '_shipping_postcode'    => $shipping_details['destination']['postcode'],
                                    '_shipping_country'     => $shipping_details['destination']['country'],
                                );

                                break;
                            }
                        }
                    }

                    // Got the shipping method and address for the package that contains current subscription?
                    if (!isset($shipping_details)) {
                        continue;
                    }

                    // Get packages based on renewal order details
                    $packages = apply_filters('woocommerce_cart_shipping_packages', array(
                        0 => array(
                            'contents'          => $renewal_cart->get_cart(),
                            'contents_cost'     => isset($renewal_cart->cart_contents[$renewal_cart_item_key]['line_total']) ? $renewal_cart->cart_contents[$renewal_cart_item_key]['line_total'] : 0,
                            'applied_coupons'   => $renewal_cart->applied_coupons,
                            'destination'       => $shipping_details['destination'],
                        ),
                    ));

                    // Now we need to calculate shipping costs but this requires overwriting session variables
                    // In order not to affect real cart, we will overwrite them but then set them back to original values
                    $original_session = array(
                        'chosen_shipping_methods'   => $woocommerce->session->get('chosen_shipping_methods'),
                        'shipping_method_counts'    => $woocommerce->session->get('shipping_method_counts'),
                    );

                    // Set fake renewal values
                    $woocommerce->session->set('chosen_shipping_methods', array($shipping_details['shipping_method']));
                    $woocommerce->session->set('shipping_method_counts', array(1));

                    // Override chosen shipping method in case there's a mismatch in shipping_method_counts (more than one available)
                    add_filter('woocommerce_shipping_chosen_method', array($this, 'set_shipping_chosen_method'));
                    $this->temp_shipping_chosen_method = $shipping_details['shipping_method'];

                    // Calculate shipping for fake renewal order now
                    $woocommerce->shipping->calculate_shipping($packages);

                    // Remove filter
                    remove_filter('woocommerce_shipping_chosen_method', array($this, 'set_shipping_chosen_method'));
                    $this->temp_shipping_chosen_method = null;
                }

                // Recalculate totals
                $renewal_cart->calculate_totals();

                // Get taxes
                foreach ($renewal_cart->get_tax_totals() as $rate_key => $rate) {
                    $renewal_order['taxes'][] = array(
                        'name'                  => $rate_key,
                        'rate_id'               => $rate->tax_rate_id,
                        'label'                 => $rate->label,
                        'compound'              => absint($rate->is_compound ? 1 : 0),
                        'tax_amount'            => wc_format_decimal(isset($renewal_cart->taxes[$rate->tax_rate_id]) ? $renewal_cart->taxes[$rate->tax_rate_id] : 0),
                        'shipping_tax_amount'   => wc_format_decimal(isset($renewal_cart->shipping_taxes[$rate->tax_rate_id]) ? $renewal_cart->shipping_taxes[$rate->tax_rate_id] : 0),
                    );
                }

                // Get renewal_order_shipping
                $renewal_order['renewal_order_shipping'] = wc_format_decimal($renewal_cart->shipping_total);

                // Get renewal_order_shipping_tax
                $renewal_order['renewal_order_shipping_tax'] = wc_format_decimal($renewal_cart->shipping_tax_total);

                // Get renewal_cart_discount
                $renewal_order['renewal_cart_discount'] = wc_format_decimal($renewal_cart->get_cart_discount_total());

                // Get renewal_order_discount
                $renewal_order['renewal_order_discount'] = wc_format_decimal($renewal_cart->get_order_discount_total());

                // Get renewal_order_tax
                $renewal_order['renewal_order_tax'] = wc_format_decimal($renewal_cart->tax_total);

                // Get renewal_order_total
                $renewal_order['renewal_order_total'] = wc_format_decimal($renewal_cart->total, get_option('woocommerce_price_num_decimals'));

                // Get renewal_line_subtotal
                $renewal_order['renewal_line_subtotal'] = wc_format_decimal($renewal_cart->cart_contents[$renewal_cart_item_key]['line_subtotal']);

                // Get renewal_line_subtotal_tax
                $renewal_order['renewal_line_subtotal_tax'] = wc_format_decimal($renewal_cart->cart_contents[$renewal_cart_item_key]['line_subtotal_tax']);

                // Get renewal_line_total
                $renewal_order['renewal_line_total'] = wc_format_decimal($renewal_cart->cart_contents[$renewal_cart_item_key]['line_total']);

                // Get renewal_line_tax
                $renewal_order['renewal_line_tax'] = wc_format_decimal($renewal_cart->cart_contents[$renewal_cart_item_key]['line_tax']);

                // Get shipping details
                if ($product->needs_shipping()) {

                    if (isset($woocommerce->shipping->packages[0]['rates'][$shipping_details['shipping_method']])) {

                        $method = $woocommerce->shipping->packages[0]['rates'][$shipping_details['shipping_method']];

                        $renewal_order['shipping'] = array(
                            'name'      => $method->label,
                            'method_id' => $method->id,
                            'cost'      => wc_format_decimal( $method->cost ),
                        );
                    }

                    // Set session variables to original values and recalculate shipping for original order which is being processed now
                    $woocommerce->session->set('chosen_shipping_methods', $original_session['chosen_shipping_methods']);
                    $woocommerce->session->set('shipping_method_counts', $original_session['shipping_method_counts']);
                    $woocommerce->shipping->calculate_shipping($packages);
                }

                // Save to object property so it can be accessed from another method
                $this->renewal_orders['by_cart_item_key'][$cart_item_key] = $renewal_order;
            }
        }
    }
 /**
  * Process the payment
  *
  * @param integer $order_id
  */
 public function process_payment($order_id)
 {
     global $wpdb;
     $order = new WC_Order($order_id);
     // fill in the product cart inside the product_info parameter
     $products = $order->get_items();
     foreach ($products as $product) {
         $product_info = $product_info . $product['name'] . ",";
     }
     $this->ok_url = $this->get_return_url($order);
     $this->ko_url = htmlspecialchars_decode(WC_Cart::get_checkout_url());
     $this->callback_url = esc_url(get_site_url() . '/index.php/wc-api/WC_GetFinancing/');
     $gf_data = array('amount' => $order->order_total, 'product_info' => $product_info, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'shipping_address' => array('street1' => $order->shipping_address_1 . " " . $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'zipcode' => $order->shipping_postcode), 'billing_address' => array('street1' => $order->billing_address_1 . " " . $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zipcode' => $order->billing_postcode), 'email' => $order->billing_email, 'phone' => $order->billing_phone, 'success_url' => $this->ok_url, 'failure_url' => $this->ko_url, 'postback_url' => $this->callback_url, 'merchant_loan_id' => (string) $order->get_order_number(), 'version' => '1.9', 'software_name' => 'woocommerce', 'software_version' => 'woocommerce ' . WC_VERSION);
     $body_json_data = json_encode($gf_data);
     $header_auth = base64_encode($this->username . ":" . $this->password);
     if ($this->environment == "test") {
         $url_to_post = $this->gateway_url_stage;
     } else {
         $url_to_post = $this->gateway_url_prod;
     }
     $url_to_post .= '/merchant/' . $this->merchant_id . '/requests';
     $post_args = array('body' => $body_json_data, 'timeout' => 60, 'blocking' => true, 'sslverify' => false, 'headers' => array('Content-Type' => 'application/json', 'Authorization' => 'Basic ' . $header_auth, 'Accept' => 'application/json'));
     //echo '<pre>' . print_r($post_args, true) . '</pre>';
     $gf_response = wp_remote_post($url_to_post, $post_args);
     //echo '<br><br><pre>' . print_r($gf_response, true) . '</pre>';
     //die();
     if (is_wp_error($gf_response)) {
         wc_add_notice('GetFinancing cannot process your order. Please try again or select a different payment method.', 'error');
         return array('result' => 'fail', 'redirect' => '');
     }
     if (isset($gf_response['body'])) {
         $response_body = json_decode($gf_response['body']);
     } else {
         wc_add_notice('GetFinancing cannot process your order. Please try again or select a different payment method.', 'error');
         return array('result' => 'fail', 'redirect' => '');
     }
     if (isset($response_body->href) == false || empty($response_body->href) == ture) {
         wc_add_notice('GetFinancing cannot process your order. Please try again or select a different payment method.', 'error');
         return array('result' => 'fail', 'redirect' => '');
     }
     // If we are here that means that the gateway give us a "created" status.
     // then we can create the order in hold status.
     global $woocommerce;
     $order = new WC_Order($order_id);
     //insert merchant_transaction_id <-> order_id relation
     $table_name = $wpdb->prefix . 'getfinancing';
     $wpdb->insert($table_name, array('order_id' => $order_id, 'merchant_transaction_id' => $response_body->inv_id));
     // order is 'pending' by default
     // we add a note to the order
     $order->add_order_note('Waiting to finish GetFinancing process!');
     // Store gf process url in session.
     WC()->session->getfinancing_process_url = $response_body->href;
     // Adds the token to the order.
     update_post_meta($order->id, 'getfinancing_custid', $response_body->customer_id);
     return array('result' => 'success', 'redirect' => $order->get_checkout_payment_url(true));
 }
 public function __construct()
 {
     _deprecated_function('woocommerce_cart', '1.4', 'WC_Cart()');
     parent::__construct();
 }
    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;
    }
            /**
             * Generate form
             * @param $order_id
             * @return string
             */
            function generate_pagantis_form($order_id)
            {
                //Logs
                $this->log->add('pagantis', 'Acceso al pago con Paga+Tarde');
                $order = new WC_Order($order_id);
                //Total Amount
                $transaction_amount = number_format((double) $order->get_total(), 2, '.', '');
                $transaction_amount = str_replace('.', '', $transaction_amount);
                $transaction_amount = floatval($transaction_amount);
                // Product Description
                $products = WC()->cart->cart_contents;
                $i = 1;
                $products_form = "";
                $description = "";
                foreach ($products as $product) {
                    $products_form .= "\r\n                  <input name='items[" . $i . "][description]' type='hidden' value='" . $product['data']->post->post_title . ' (' . $product['quantity'] . ')' . "'>\r\n                  <input name='items[" . $i . "][quantity]' type='hidden' value='" . $product['quantity'] . "'>\r\n                  <input name='items[" . $i . "][amount]' type='hidden' value='" . round(($product['data']->price + $product['line_tax']) * $product['quantity'], 2) . "'>\r\n                  ";
                    $description[] = $product['data']->post->post_title . ' (' . $product['quantity'] . ')';
                    $i++;
                }
                $shipping = $order->get_items('shipping');
                foreach ($shipping as $shipping_method) {
                    if ($shipping_method['cost'] > 0) {
                        $products_form .= "\r\n                    <input name='items[" . $i . "][description]' type='hidden' value='" . __('Gastos de envio', 'pagantis') . "'>\r\n                    <input name='items[" . $i . "][quantity]' type='hidden' value='1'>\r\n                    <input name='items[" . $i . "][amount]' type='hidden' value='" . $shipping_method['cost'] . "'>\r\n                    ";
                        $description[] = 'Gastos de envio';
                        $i++;
                    }
                }
                $account_id = "";
                $dataToEncode = "";
                $this->ok_url = $this->get_return_url($order);
                $this->ko_url = htmlspecialchars_decode(WC_Cart::get_checkout_url());
                $this->cancelled_url = htmlspecialchars_decode(WC_Cart::get_checkout_url());
                //Test Environment Selected
                if ($this->environment == self::TEST_ENVIRONMENT) {
                    $this->key = $this->test_key;
                    $dataToEncode = $this->test_key . $this->test_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url . $this->discount . $this->cancelled_url;
                    $account_id = $this->test_account;
                } else {
                    $this->key = $this->real_key;
                    $dataToEncode = $this->real_key . $this->real_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url . $this->discount . $this->cancelled_url;
                    $account_id = $this->real_account;
                }
                $signature = hash('sha512', $dataToEncode);
                $form_url = $this->paga_mastarde_url;
                $adressInfo = explode("/", $order->billing_city);
                $customer = new WC_Customer();
                $countries = new WC_Countries();
                $address = $customer->get_address() . " " . $customer->get_address_2();
                $city = $customer->get_city();
                $postcode = $customer->get_postcode();
                $states = $countries->get_states();
                $state = $states[$order->shipping_country][$customer->get_state()];
                $saddress = $customer->shipping_address_1 . " " . $customer->shipping_address_2;
                $scity = $customer->shipping_city;
                $spostcode = $customer->shipping_postcode;
                $sstate = $states[$order->shipping_country][$customer->shipping_state];
                //Create Form
                $buyer_name = $order->billing_first_name . " " . $order->billing_last_name;
                $pagantis_form_fields = "\r\n                <input name='order_id' type='hidden' value='" . $order_id . "' />\r\n                <input name='amount' type='hidden' value='" . $transaction_amount . "' />\r\n                <input name='currency' type='hidden' value='" . $this->currency . "' />\r\n\r\n                <input name='ok_url' type='hidden' value='" . $this->ok_url . "' />\r\n                <input name='nok_url' type='hidden' value='" . $this->ko_url . "' />\r\n                <input name='cancelled_url' type='hidden' value='" . $this->cancelled_url . "' />\r\n\r\n                <input name='locale' type='hidden' value='" . $this->lang . "' />\r\n\r\n                <input name='full_name' type='hidden' value='" . $buyer_name . "'>\r\n                <input name='email' type='hidden' value='" . $order->billing_email . "'>\r\n\r\n                " . $products_form . "\r\n\r\n                <!-- firma de la operación -->\r\n                <input name='account_id' type='hidden' value='" . $account_id . "' />\r\n                <input name='signature' type='hidden' value='" . $signature . "' />\r\n\r\n                <!-- discount -->\r\n                <input name='discount[full]' type='hidden' value='" . $this->discount . "' />\r\n                <input name='iframe' type='hidden' value='" . $this->iframe . "' />\r\n\r\n                <!-- callback url -->\r\n                <input name='callback_url' type='hidden' value='" . $this->callback_url . "' />\r\n\r\n                <input name='description' type='hidden' value='" . implode(',', $description) . "' />\r\n\r\n                <!-- address -->\r\n                <input name='address[street]' type='hidden' value='" . $address . "'>\r\n                <input name='address[city]' type='hidden' value='" . $city . "'>\r\n                <input name='address[province]' type='hidden' value='" . $state . "'>\r\n                <input name='address[zipcode]' type='hidden' value='" . $postcode . "'>\r\n\r\n                <input name='shipping[street]' type='hidden' value='" . $saddress . "'>\r\n                <input name='shipping[city]' type='hidden' value='" . $scity . "'>\r\n                <input name='shipping[province]' type='hidden' value='" . $sstate . "'>\r\n                <input name='shipping[zipcode]' type='hidden' value='" . $spostcode . "'>\r\n\r\n                <!-- phone -->\r\n\r\n                <input name='mobile_phone' type='hidden' value='" . $order->billing_phone . "'>\r\n                ";
                $return_form = '<form action="' . $form_url . '" method="post" id="pagantis_payment_form">
                ' . $pagantis_form_fields . '
                <input type="submit" class="button-alt" id="submit_vme_payment_form" value="' . __('Realizar el pago', 'pagantis') . '" />

                </form>';
                if ($this->iframe == 'true') {
                    wp_enqueue_style('style', esc_url(plugins_url('pages/assets/css/iframe.css', __FILE__)));
                    $return_form .= '<div id="myModal" class="paylater_modal">
                    <!-- Modal content -->
                    <div class="paylater_modal-content">
                      <span id="paylater_close">x</span>
                      <iframe id="iframe-pagantis" name="iframe-pagantis" style="width:100%;height:600px;display:block"></iframe>
                    </div>
                  </div>';
                    $return_form .= '<script type="text/javascript">
                  el = document.getElementById("submit_vme_payment_form");
                  el.addEventListener("click", function (e){
                    e.preventDefault();
                    document.getElementById("pagantis_payment_form").setAttribute("target", "iframe-pagantis");
                    document.getElementById("pagantis_payment_form").submit();
                    document.getElementById("iframe-pagantis").style.display = "block";
                    document.getElementById("myModal").style.display = "block";
                  });

                  var closeModal = function closeModal(evt) {
                   evt.preventDefault();
                   document.getElementById("myModal").style.display = "none";
                  };

                  var elements = document.querySelectorAll("#paylater_close, #myModal");
                   Array.prototype.forEach.call(elements, function(el){
                   el.addEventListener("click", closeModal);
                  });

                  document.addEventListener("DOMContentLoaded", function(event) {
                    document.getElementById("pagantis_payment_form").setAttribute("target", "iframe-pagantis");
                    document.getElementById("pagantis_payment_form").submit();
                    document.getElementById("iframe-pagantis").style.display = "block";
                    document.getElementById("myModal").style.display = "block";
                    });
                  </script>';
                } else {
                    $return_form .= "<script type='text/javascript'>\r\n                  jQuery(document).ready(function() {\r\n                    jQuery('#submit_vme_payment_form').click();\r\n                  });\r\n                  </script>";
                }
                return $return_form;
            }
Example #12
0
    public static function rac_send_manual_mail()
    {
        global $wpdb, $woocommerce, $to, $user_lang;
        $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']);
        $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';
        ?>
        <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 = "<table style='width:100%;border:1px solid #eee;'><thead><tr>";
            if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_name', $cart_row[0]->wpml_lang, get_option('rac_product_info_product_name')) . "</th>";
            }
            if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_image', $cart_row[0]->wpml_lang, get_option('rac_product_info_product_image')) . "</th>";
            }
            if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_price', $cart_row[0]->wpml_lang, get_option('rac_product_info_product_price')) . "</th>";
            }
            $tablecheckproduct .= "</tr></thead><tbody>";
            if (is_array($cart_array)) {
                $i = 1;
                foreach ($cart_array as $cart) {
                    if (is_array($cart)) {
                        foreach ($cart as $inside) {
                            if (is_array($inside)) {
                                foreach ($inside as $product) {
                                    if ($cart_row[0]->user_id != '0' && $cart_row[0]->user_id != 'old_order') {
                                        if ((double) $woocommerce->version <= (double) '2.0.20') {
                                            $objectproduct = get_product($product['product_id']);
                                            $objectproductvariable = get_product($product['variation_id']);
                                        } else {
                                            $objectproduct = new WC_Product($product['product_id']);
                                            $objectproductvariable = new WC_Product_Variation($product['variation_id']);
                                        }
                                        $tablecheckproduct .= "<tr>";
                                        if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                                            $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_title($product['product_id']) . "</td>";
                                        }
                                        if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                                            $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_post_thumbnail($product['product_id'], array(90, 90)) . "</td>";
                                        }
                                        if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                                            $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . FPRacCron::get_rac_formatprice($product['variation_id'] == '' ? $objectproduct->get_price() : $objectproductvariable->get_price()) . "</td>";
                                        }
                                        $tablecheckproduct .= "</tr>";
                                    }
                                }
                            }
                        }
                    } else {
                        if ($i == '3') {
                            $get_array_keys = array_keys($cart_array);
                            $product_id = $cart_array[$get_array_keys[0]]['product_id'];
                            $variation_id = $cart_array[$get_array_keys[0]]['variation_id'];
                            if ((double) $woocommerce->version <= (double) '2.0.20') {
                                $objectproduct = get_product($product_id);
                                $objectproductvariable = get_product($variation_id);
                            } else {
                                $objectproduct = new WC_Product($product_id);
                                $objectproductvariable = new WC_Product_Variation($variation_id);
                            }
                            $tablecheckproduct .= "<tr>";
                            if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                                $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_title($product_id) . "</td>";
                            }
                            if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                                $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_post_thumbnail($product_id, array(90, 90)) . "</td>";
                            }
                            if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                                $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . FPRacCron::get_rac_formatprice($variation_id == '' ? $objectproduct->get_price() : $objectproductvariable->get_price()) . "</td>";
                            }
                            $tablecheckproduct .= "</tr>";
                        }
                        $i++;
                    }
                }
            } elseif (is_object($cart_array)) {
                $order = new WC_Order($cart_array->id);
                //  if ($order->user_id != '') {
                foreach ($order->get_items() as $products) {
                    if ((double) $woocommerce->version <= (double) '2.0.20') {
                        $objectproduct = get_product($products['product_id']);
                        $objectproductvariable = get_product($products['variation_id']);
                    } else {
                        $objectproduct = new WC_Product($products['product_id']);
                        $objectproductvariable = new WC_Product_Variation($products['variation_id']);
                    }
                    $tablecheckproduct .= "<tr>";
                    if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                        $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_title($products['product_id']) . "</td>";
                    }
                    if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                        $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_post_thumbnail($products['product_id'], array(90, 90)) . "</td>";
                    }
                    if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                        $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . FPRacCron::get_rac_formatprice($products['line_total']) . "</td>";
                    }
                    $tablecheckproduct .= "</tr>";
                }
                //}
            }
            $tablecheckproduct .= "</table>";
            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;
                $user_lang = $cart_row[0]->wpml_lang;
                $firstname = $user->user_firstname;
                $lastname = $user->user_lastname;
                $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);
                    $message = str_replace('{rac.coupon}', $coupon_code, $message);
                    //replacing shortcode with coupon code
                }
                add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                $message = do_shortcode($message);
                //shortcode feature
                if (get_option('rac_email_use_temp_plain') != 'yes') {
                    ob_start();
                    if (function_exists('wc_get_template')) {
                        wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                        echo $message;
                        wc_get_template('emails/email-footer.php');
                    } else {
                        woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                        echo $message;
                        woocommerce_get_template('emails/email-footer.php');
                    }
                    $woo_temp_msg = ob_get_clean();
                } else {
                    $woo_temp_msg = $message;
                }
                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;
                $user_lang = $cart_row[0]->wpml_lang;
                $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);
                    $message = str_replace('{rac.coupon}', $coupon_code, $message);
                    //replacing shortcode with coupon code
                }
                $message = do_shortcode($message);
                //shortcode feature
                add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                if (get_option('rac_email_use_temp_plain') != 'yes') {
                    ob_start();
                    if (function_exists('wc_get_template')) {
                        wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                        echo $message;
                        wc_get_template('emails/email-footer.php');
                    } else {
                        woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                        echo $message;
                        woocommerce_get_template('emails/email-footer.php');
                    }
                    $woo_temp_msg = ob_get_clean();
                } else {
                    $woo_temp_msg = $message;
                }
                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' => $each_cart->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" => $each_cart->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($each_cart->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'];
                $user_lang = $cart_row[0]->wpml_lang;
                $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);
                    $message = str_replace('{rac.coupon}', $coupon_code, $message);
                    //replacing shortcode with coupon code
                }
                $message = do_shortcode($message);
                //shortcode feature
                if (get_option('rac_email_use_temp_plain') != 'yes') {
                    ob_start();
                    if (function_exists('wc_get_template')) {
                        wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                        echo $message;
                        wc_get_template('emails/email-footer.php');
                    } else {
                        woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                        echo $message;
                        woocommerce_get_template('emails/email-footer.php');
                    }
                    $woo_temp_msg = ob_get_clean();
                } else {
                    $woo_temp_msg = $message;
                }
                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[] = $emails->id;
                        $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;
                $user_lang = $cart_row[0]->wpml_lang;
                $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);
                    $message = str_replace('{rac.coupon}', $coupon_code, $message);
                    //replacing shortcode with coupon code
                }
                $message = do_shortcode($message);
                //shortcode feature
                if (get_option('rac_email_use_temp_plain') != 'yes') {
                    ob_start();
                    if (function_exists('wc_get_template')) {
                        wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                        echo $message;
                        wc_get_template('emails/email-footer.php');
                    } else {
                        woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                        echo $message;
                        woocommerce_get_template('emails/email-footer.php');
                    }
                    $woo_temp_msg = ob_get_clean();
                } else {
                    $woo_temp_msg = $message;
                }
                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;
    }
Example #13
0
function update_cart_before_checkout()
{
    $cart = new WC_Cart();
    $cart->calculate_totals();
}
 /**
  * Stores shipping info on the subscription
  *
  * @param WC_Subscription $subscription instance of a subscriptions object
  * @param WC_Cart $cart A cart with recurring items in it
  */
 public static function add_shipping($subscription, $cart)
 {
     foreach ($cart->get_shipping_packages() as $base_package) {
         $package = WC()->shipping->calculate_shipping_for_package($base_package);
         foreach (WC()->shipping->get_packages() as $package_key => $package_to_ignore) {
             if (isset($package['rates'][WC()->checkout()->shipping_methods[$package_key]])) {
                 $item_id = $subscription->add_shipping($package['rates'][WC()->checkout()->shipping_methods[$package_key]]);
                 if (!$item_id) {
                     throw new Exception(__('Error: Unable to create subscription. Please try again.', 'woocommerce-subscriptions'));
                 }
                 // Allows plugins to add order item meta to shipping
                 do_action('woocommerce_add_shipping_order_item', $subscription->id, $item_id, $package_key);
                 do_action('woocommerce_subscriptions_add_recurring_shipping_order_item', $subscription->id, $item_id, $package_key);
             }
         }
     }
 }
Example #15
0
 public static function fp_rac_cron_job_mailing()
 {
     global $wpdb;
     global $woocommerce;
     global $to;
     global $user_lang;
     $emailtemplate_table_name = $wpdb->prefix . 'rac_templates_email';
     $abandancart_table_name = $wpdb->prefix . 'rac_abandoncart';
     $email_templates = $wpdb->get_results("SELECT * FROM {$emailtemplate_table_name}");
     //all email templates
     $abandon_carts = $wpdb->get_results("SELECT * FROM {$abandancart_table_name} WHERE cart_status='ABANDON' AND user_id!='0' AND completed IS NULL");
     //Selected only cart which are not completed
     // For Members
     foreach ($abandon_carts as $each_cart) {
         foreach ($email_templates as $emails) {
             if ($emails->status == "ACTIVE") {
                 $cart_array = maybe_unserialize($each_cart->cart_details);
                 $tablecheckproduct = "<table style='width:100%;border:1px solid #eee;'><thead><tr>";
                 if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                     $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_name', $each_cart->wpml_lang, get_option('rac_product_info_product_name')) . "</th>";
                 }
                 if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                     $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_image', $each_cart->wpml_lang, get_option('rac_product_info_product_image')) . "</th>";
                 }
                 if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                     $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_price', $each_cart->wpml_lang, get_option('rac_product_info_product_price')) . "</th>";
                 }
                 $tablecheckproduct .= "</tr></thead><tbody>";
                 if (is_array($cart_array)) {
                     foreach ($cart_array as $cart) {
                         foreach ($cart as $inside) {
                             foreach ($inside as $product) {
                                 if ((double) $woocommerce->version <= (double) '2.0.20') {
                                     $objectproduct = get_product($product['product_id']);
                                     $objectproductvariable = get_product($product['variation_id']);
                                 } else {
                                     $objectproduct = new WC_Product($product['product_id']);
                                     $objectproductvariable = new WC_Product_Variation($product['variation_id']);
                                 }
                                 $tablecheckproduct .= "<tr>";
                                 if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                                     $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_title($product['product_id']) . "</td>";
                                 }
                                 if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                                     $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_post_thumbnail($product['product_id'], array(90, 90)) . "</td>";
                                 }
                                 if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                                     $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . self::get_rac_formatprice($product['variation_id'] == '' ? $objectproduct->get_price() : $objectproductvariable->get_price()) . "</td>";
                                 }
                                 $tablecheckproduct .= "</tr>";
                             }
                         }
                     }
                     /* $tablecheckproduct .= "It is from Array";
                        $dump = print_r($cart_array, true);
                        $tablecheckproduct .= $dump; */
                 } elseif (is_object($cart_array)) {
                     $order = new WC_Order($cart_array->id);
                     if ($order->user_id != '') {
                         foreach ($order->get_items() as $products) {
                             if ((double) $woocommerce->version <= (double) '2.0.20') {
                                 $objectproduct = get_product($products['product_id']);
                                 $objectproductvariable = get_product($products['variation_id']);
                             } else {
                                 $objectproduct = new WC_Product($products['product_id']);
                                 $objectproductvariable = new WC_Product_Variation($products['variation_id']);
                             }
                             $tablecheckproduct .= "<tr>";
                             if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                                 $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_title($products['product_id']) . "</td>";
                             }
                             if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                                 $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_post_thumbnail($products['product_id'], array(90, 90)) . "</td>";
                             }
                             if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                                 $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . self::get_rac_formatprice($products['variation_id'] == '' ? $objectproduct->get_price() : $objectproductvariable->get_price()) . "</td>";
                             }
                             $tablecheckproduct .= "</tr>";
                         }
                     }
                     /*  $tablecheckproduct .= "It is from Object";
                         $tablecheckproduct .= var_dump($cart_array); */
                 }
                 $tablecheckproduct .= "</table>";
                 if (get_option('rac_email_use_members') == 'yes') {
                     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 = $woocommerce->cart->get_cart_url();
                             //$objectcart = new WC_Cart();
                             @($cart_url = WC_Cart::get_cart_url());
                             $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id), $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_' . $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);
                             }
                             $user = get_userdata($each_cart->user_id);
                             $to = $user->user_email;
                             $user_lang = $each_cart->wpml_lang;
                             $subject = fp_get_wpml_text('rac_template_' . $emails->id . '_subject', $each_cart->wpml_lang, $emails->subject);
                             $firstname = $user->user_firstname;
                             $lastname = $user->user_lastname;
                             $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($user->user_email, $each_cart->cart_abandon_time);
                                 $message = str_replace('{rac.coupon}', $coupon_code, $message);
                                 //replacing shortcode with coupon code
                             }
                             add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                             $message = do_shortcode($message);
                             //shortcode feature
                             if (get_option('rac_email_use_temp_plain') != 'yes') {
                                 ob_start();
                                 if (function_exists('wc_get_template')) {
                                     wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                                     echo $message;
                                     wc_get_template('emails/email-footer.php');
                                 } else {
                                     woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                                     echo $message;
                                     woocommerce_get_template('emails/email-footer.php');
                                 }
                                 $woo_temp_msg = ob_get_clean();
                             } else {
                                 $woo_temp_msg = $message;
                             }
                             $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)) {
                                         //  wp_mail($to, $subject, $message);
                                         $store_template_id = array($emails->id);
                                         $store_template_id = maybe_serialize($store_template_id);
                                         $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                                         //add to mail log
                                         $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)) {
                                         //  wp_mail($to, $subject, $message);
                                         $store_template_id = array($emails->id);
                                         $store_template_id = maybe_serialize($store_template_id);
                                         $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                                         //add to mail log
                                         $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());
                                 $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id), $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_' . $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);
                                 }
                                 $user = get_userdata($each_cart->user_id);
                                 $to = $user->user_email;
                                 $user_lang = $each_cart->wpml_lang;
                                 $subject = fp_get_wpml_text('rac_template_' . $emails->id . '_subject', $each_cart->wpml_lang, $emails->subject);
                                 $firstname = $user->user_firstname;
                                 $lastname = $user->user_lastname;
                                 $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($user->user_email, $each_cart->cart_abandon_time);
                                     $message = str_replace('{rac.coupon}', $coupon_code, $message);
                                     //replacing shortcode with coupon code
                                 }
                                 add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                                 $message = do_shortcode($message);
                                 //shortcode feature
                                 if (get_option('rac_email_use_temp_plain') != 'yes') {
                                     ob_start();
                                     if (function_exists('wc_get_template')) {
                                         wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                                         echo $message;
                                         wc_get_template('emails/email-footer.php');
                                     } else {
                                         woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                                         echo $message;
                                         woocommerce_get_template('emails/email-footer.php');
                                     }
                                     $woo_temp_msg = ob_get_clean();
                                 } else {
                                     $woo_temp_msg = $message;
                                 }
                                 $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)) {
                                             //wp_mail($to, $subject, $message);
                                             $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));
                                             //add to mail log
                                             $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)) {
                                             //wp_mail($to, $subject, $message);
                                             $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));
                                             //add to mail log
                                             $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();
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // FOR GUEST
     if (get_option('rac_email_use_guests') == 'yes') {
         $abandon_carts = $wpdb->get_results("SELECT * FROM {$abandancart_table_name} WHERE cart_status='ABANDON' AND user_id='0' AND ip_address IS NULL AND completed IS NULL");
         //Selected only cart which are not completed
         foreach ($abandon_carts as $each_cart) {
             foreach ($email_templates as $emails) {
                 if ($emails->status == "ACTIVE") {
                     $cart_array = maybe_unserialize($each_cart->cart_details);
                     $tablecheckproduct = "<table style='width:100%;border:1px solid #eee;'><thead><tr>";
                     if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                         $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_name', $each_cart->wpml_lang, get_option('rac_product_info_product_name')) . "</th>";
                     }
                     if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                         $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_image', $each_cart->wpml_lang, get_option('rac_product_info_product_image')) . "</th>";
                     }
                     if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                         $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_price', $each_cart->wpml_lang, get_option('rac_product_info_product_price')) . "</th>";
                     }
                     $tablecheckproduct .= "</tr></thead><tbody>";
                     $order = new WC_Order($cart_array->id);
                     $products = $order->get_items();
                     //var_dump($products);
                     /* $tablecheckproduct .= "It is from Guest0 Object or Array";
                        $dump = print_r($cart_array, true);
                        $tablecheckproduct .= "<pre>";
                        $tablecheckproduct .= $dump;
                        $tablecheckproduct .= "</pre>"; */
                     foreach ($products as $each_product) {
                         if ((double) $woocommerce->version <= (double) '2.0.20') {
                             $objectproduct = get_product($each_product['product_id']);
                             $objectproductvariable = get_product($each_product['variation_id']);
                         } else {
                             $objectproduct = new WC_Product($each_product['product_id']);
                             $objectproductvariable = new WC_Product_Variable($each_product['variation_id']);
                         }
                         $tablecheckproduct .= "<tr>";
                         if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                             $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_title($each_product['product_id']) . "</td>";
                         }
                         if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                             $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_post_thumbnail($each_product['product_id'], array(90, 90)) . "</td>";
                         }
                         if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                             $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . self::get_rac_formatprice($each_product['variation_id'] == '' ? $objectproduct->get_price() : $objectproductvariable->get_price()) . "</td>";
                         }
                         $tablecheckproduct .= "</tr>";
                     }
                     $tablecheckproduct .= "</table>";
                     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());
                             $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'guest' => '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_' . $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);
                             }
                             //  $user = get_userdata($each_cart->user_id); NOT APPLICABLE
                             //                                echo "<pre>";
                             //                                var_dump($each_cart->cart_details);
                             //                                echo "</pre>";
                             @($order_object = maybe_unserialize($each_cart->cart_details));
                             // $order_objectinfo = maybe_unserialize($productifo->cart_details);
                             $to = $order_object->billing_email;
                             $user_lang = $each_cart->wpml_lang;
                             $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;
                             $message = fp_get_wpml_text('rac_template_' . $emails->id . '_message', $each_cart->wpml_lang, $emails->message);
                             $message = str_replace('{rac.cartlink}', $url_to_click, $message);
                             $subject = RecoverAbandonCart::shortcode_in_subject($firstname, $lastname, $subject);
                             $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, $each_cart->cart_abandon_time);
                                 $message = str_replace('{rac.coupon}', $coupon_code, $message);
                                 //replacing shortcode with coupon code
                             }
                             add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                             $message = do_shortcode($message);
                             //shortcode feature
                             if (get_option('rac_email_use_temp_plain') != 'yes') {
                                 ob_start();
                                 if (function_exists('wc_get_template')) {
                                     wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                                     echo $message;
                                     wc_get_template('emails/email-footer.php');
                                 } else {
                                     woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                                     echo $message;
                                     woocommerce_get_template('emails/email-footer.php');
                                 }
                                 $woo_temp_msg = ob_get_clean();
                             } else {
                                 $woo_temp_msg = $message;
                             }
                             $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)) {
                                         // wp_mail($to, $subject, $message);
                                         $store_template_id = array($emails->id);
                                         $store_template_id = maybe_serialize($store_template_id);
                                         $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                                         //add to mail log
                                         $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)) {
                                         // wp_mail($to, $subject, $message);
                                         $store_template_id = array($emails->id);
                                         $store_template_id = maybe_serialize($store_template_id);
                                         $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                                         //add to mail log
                                         $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());
                                     $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'guest' => '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_' . $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);
                                     }
                                     //  $user = get_userdata($each_cart->user_id); NOT APPLICABLE
                                     $order_object = maybe_unserialize($each_cart->cart_details);
                                     $to = $order_object->billing_email;
                                     $user_lang = $each_cart->wpml_lang;
                                     $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;
                                     $message = fp_get_wpml_text('rac_template_' . $emails->id . '_message', $each_cart->wpml_lang, $emails->message);
                                     $message = str_replace('{rac.cartlink}', $url_to_click, $message);
                                     $subject = RecoverAbandonCart::shortcode_in_subject($firstname, $lastname, $subject);
                                     $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, $each_cart->cart_abandon_time);
                                         $message = str_replace('{rac.coupon}', $coupon_code, $message);
                                         //replacing shortcode with coupon code
                                     }
                                     add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                                     $message = do_shortcode($message);
                                     //shortcode feature
                                     if (get_option('rac_email_use_temp_plain') != 'yes') {
                                         ob_start();
                                         if (function_exists('wc_get_template')) {
                                             wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                                             echo $message;
                                             wc_get_template('emails/email-footer.php');
                                         } else {
                                             woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                                             echo $message;
                                             woocommerce_get_template('emails/email-footer.php');
                                         }
                                         $woo_temp_msg = ob_get_clean();
                                     } else {
                                         $woo_temp_msg = $message;
                                     }
                                     $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)) {
                                                 // wp_mail($to, $subject, $message);
                                                 $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));
                                                 //add to mail log
                                                 $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)) {
                                                 // wp_mail($to, $subject, $message);
                                                 $store_template_id = array($emails->id);
                                                 $store_template_id = maybe_serialize($store_template_id);
                                                 $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                                                 //add to mail log
                                                 $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();
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         //FOR Guest Captured in chcekout page
         $abandon_carts = $wpdb->get_results("SELECT * FROM {$abandancart_table_name} WHERE cart_status='ABANDON' AND user_id='0' AND ip_address IS NOT NULL AND completed IS NULL");
         //Selected only cart which are not completed
         foreach ($abandon_carts as $each_cart) {
             foreach ($email_templates as $emails) {
                 $cart_array = maybe_unserialize($each_cart->cart_details);
                 $tablecheckproduct = "<table style='width:100%;border:1px solid #eee;'><thead><tr>";
                 if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                     $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_name', $each_cart->wpml_lang, get_option('rac_product_info_product_name')) . "</th>";
                 }
                 if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                     $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_image', $each_cart->wpml_lang, get_option('rac_product_info_product_image')) . "</th>";
                 }
                 if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                     $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_price', $each_cart->wpml_lang, get_option('rac_product_info_product_price')) . "</th>";
                 }
                 $tablecheckproduct .= "</tr></thead><tbody>";
                 if (is_array($cart_array)) {
                     /* $tablecheckproduct .= "It is from Guest Array";
                        $dump = print_r($cart_array, true);
                        $tablecheckproduct .= "<pre>";
                        $tablecheckproduct .= $dump;
                        $tablecheckproduct .= "</pre>"; */
                     foreach ($cart_array as $cart) {
                         if (is_array($cart)) {
                             if ((double) $woocommerce->version <= (double) '2.0.20') {
                                 $objectproduct = get_product($cart['product_id']);
                                 $objectproductvariable = get_product($cart['variation_id']);
                             } else {
                                 $objectproduct = new WC_Product($cart['product_id']);
                                 $objectproductvariable = new WC_Product_Variable($cart['variation_id']);
                             }
                             $tablecheckproduct .= "<tr>";
                             if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                                 $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_title($cart['product_id']) . "</td>";
                             }
                             if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                                 $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_post_thumbnail($cart['product_id'], array(90, 90)) . "</td>";
                             }
                             if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                                 $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . self::get_rac_formatprice($cart['variation_id'] == '' ? $objectproduct->get_price() : $objectproductvariable->get_price()) . "</td>";
                             }
                             $tablecheckproduct .= "</tr>";
                         }
                     }
                 } elseif (is_object($cart_array)) {
                     /* $tablecheckproduct .= "It is from Guest1 Object";
                        $dump = print_r($cart_array, true);
                        $tablecheckproduct .= $dump; */
                     $order = new WC_Order($cart_array->id);
                     //                        if ($order->user_id != '') {
                     foreach ($order->get_items() as $products) {
                         if ((double) $woocommerce->version <= (double) '2.0.20') {
                             $objectproduct = get_product($products['product_id']);
                             $objectproductvariable = get_product($products['variation_id']);
                         } else {
                             $objectproduct = new WC_Product($products['product_id']);
                             $objectproductvariable = new WC_Product_Variable($products['variation_id']);
                         }
                         $tablecheckproduct .= "<tr>";
                         if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                             $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_title($products['product_id']) . "</td>";
                         }
                         if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                             $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_post_thumbnail($products['product_id'], array(90, 90)) . "</td>";
                         }
                         if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                             $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . self::get_rac_formatprice($products['variation_id'] == '' ? $objectproduct->get_price() : $objectproductvariable->get_price()) . "</td>";
                         }
                         $tablecheckproduct .= "</tr>";
                     }
                     //  }
                 }
                 $tablecheckproduct .= "</table>";
                 if ($emails->status == "ACTIVE") {
                     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());
                             $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));
                             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);
                             }
                             //  $user = get_userdata($each_cart->user_id); NOT APPLICABLE
                             $order_object = maybe_unserialize($each_cart->cart_details);
                             $to = $order_object['visitor_mail'];
                             $user_lang = $each_cart->wpml_lang;
                             $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'];
                             $message = fp_get_wpml_text('rac_template_' . $emails->id . '_message', $each_cart->wpml_lang, $emails->message);
                             $message = str_replace('{rac.cartlink}', $url_to_click, $message);
                             $subject = RecoverAbandonCart::shortcode_in_subject($firstname, $lastname, $subject);
                             $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'], $each_cart->cart_abandon_time);
                                 $message = str_replace('{rac.coupon}', $coupon_code, $message);
                                 //replacing shortcode with coupon code
                             }
                             add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                             $message = do_shortcode($message);
                             //shortcode feature
                             if (get_option('rac_email_use_temp_plain') != 'yes') {
                                 ob_start();
                                 if (function_exists('wc_get_template')) {
                                     wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                                     echo $message;
                                     wc_get_template('emails/email-footer.php');
                                 } else {
                                     woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                                     echo $message;
                                     woocommerce_get_template('emails/email-footer.php');
                                 }
                                 $woo_temp_msg = ob_get_clean();
                             } else {
                                 $woo_temp_msg = $message;
                             }
                             $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')) {
                                     //  var_dump($to,$subject,$woo_temp_msg,$headers);
                                     if (self::rac_send_wp_mail($to, $subject, $woo_temp_msg, $headers)) {
                                         // wp_mail($to, $subject, $message);
                                         $store_template_id = array($emails->id);
                                         $store_template_id = maybe_serialize($store_template_id);
                                         $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                                         //add to mail log
                                         $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)) {
                                         // wp_mail($to, $subject, $message);
                                         $store_template_id = array($emails->id);
                                         $store_template_id = maybe_serialize($store_template_id);
                                         $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                                         //add to mail log
                                         $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());
                                 $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));
                                 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);
                                 }
                                 //  $user = get_userdata($each_cart->user_id); NOT APPLICABLE
                                 $order_object = maybe_unserialize($each_cart->cart_details);
                                 $to = $order_object['visitor_mail'];
                                 $user_lang = $each_cart->wpml_lang;
                                 $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'];
                                 $message = fp_get_wpml_text('rac_template_' . $emails->id . '_message', $each_cart->wpml_lang, $emails->message);
                                 $message = str_replace('{rac.cartlink}', $url_to_click, $message);
                                 $subject = RecoverAbandonCart::shortcode_in_subject($firstname, $lastname, $subject);
                                 $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'], $each_cart->cart_abandon_time);
                                     $message = str_replace('{rac.coupon}', $coupon_code, $message);
                                     //replacing shortcode with coupon code
                                 }
                                 add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                                 $message = do_shortcode($message);
                                 //shortcode feature
                                 if (get_option('rac_email_use_temp_plain') != 'yes') {
                                     ob_start();
                                     if (function_exists('wc_get_template')) {
                                         wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                                         echo $message;
                                         wc_get_template('emails/email-footer.php');
                                     } else {
                                         woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                                         echo $message;
                                         woocommerce_get_template('emails/email-footer.php');
                                     }
                                     $woo_temp_msg = ob_get_clean();
                                 } else {
                                     $woo_temp_msg = $message;
                                 }
                                 $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)) {
                                             // wp_mail($to, $subject, $message);
                                             $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));
                                             //add to mail log
                                             $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)) {
                                             // wp_mail($to, $subject, $message);
                                             $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));
                                             //add to mail log
                                             $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();
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // FOR ORDER UPDATED FROM OLD
     $abandon_carts = $wpdb->get_results("SELECT * FROM {$abandancart_table_name} WHERE cart_status='ABANDON' AND user_id='old_order' AND ip_address IS NULL AND completed IS NULL");
     //Selected only cart which are not completed
     foreach ($abandon_carts as $each_cart) {
         foreach ($email_templates as $emails) {
             $cart_array = maybe_unserialize($each_cart->cart_details);
             $tablecheckproduct = "<table style='width:100%;border:1px solid #eee;'><thead><tr>";
             if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                 $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_name', $each_cart->wpml_lang, get_option('rac_product_info_product_name')) . "</th>";
             }
             if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                 $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_image', $each_cart->wpml_lang, get_option('rac_product_info_product_image')) . "</th>";
             }
             if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                 $tablecheckproduct .= "<th style='text-align:left;border:1px solid #eee;padding:12px' scope='col'>" . fp_get_wpml_text('rac_template_product_price', $each_cart->wpml_lang, get_option('rac_product_info_product_price')) . "</th>";
             }
             $tablecheckproduct .= "</tr></thead><tbody>";
             if (is_object($cart_array)) {
                 if (get_option('rac_email_use_members') == 'yes') {
                     /* $tablecheckproduct .= "It is from Member Object";
                        $dump = print_r($cart_array, true);
                        $tablecheckproduct .= $dump; */
                     $order = new WC_Order($cart_array->id);
                     if ($order->user_id != '') {
                         foreach ($order->get_items() as $products) {
                             if ((double) $woocommerce->version <= (double) '2.0.20') {
                                 $objectproduct = get_product($products['product_id']);
                                 $objectproductvariable = get_product($products['variation_id']);
                             } else {
                                 $objectproduct = new WC_Product($products['product_id']);
                                 $objectproductvariable = new WC_Product_Variable($products['variation_id']);
                             }
                             $tablecheckproduct .= "<tr>";
                             if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                                 $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_title($products['product_id']) . "</td>";
                             }
                             if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                                 $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_post_thumbnail($products['product_id'], array(90, 90)) . "</td>";
                             }
                             if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                                 $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . self::get_rac_formatprice($products['variation_id'] == '' ? $objectproduct->get_price() : $objectproductvariable->get_price()) . "</td>";
                             }
                             $tablecheckproduct .= "</tr>";
                         }
                     }
                     //mail
                     if ($emails->status == "ACTIVE") {
                         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());
                                 $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'old_order' => '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_' . $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);
                                 }
                                 //  $user = get_userdata($each_cart->user_id); NOT APPLICABLE
                                 $order_object = maybe_unserialize($each_cart->cart_details);
                                 $to = $order_object->billing_email;
                                 $user_lang = $each_cart->wpml_lang;
                                 $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;
                                 $message = fp_get_wpml_text('rac_template_' . $emails->id . '_message', $each_cart->wpml_lang, $emails->message);
                                 $message = str_replace('{rac.cartlink}', $url_to_click, $message);
                                 $subject = RecoverAbandonCart::shortcode_in_subject($firstname, $lastname, $subject);
                                 $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, $each_cart->cart_abandon_time);
                                     $message = str_replace('{rac.coupon}', $coupon_code, $message);
                                     //replacing shortcode with coupon code
                                 }
                                 add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                                 $message = do_shortcode($message);
                                 //shortcode feature
                                 if (get_option('rac_email_use_temp_plain') != 'yes') {
                                     ob_start();
                                     if (function_exists('wc_get_template')) {
                                         wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                                         echo $message;
                                         wc_get_template('emails/email-footer.php');
                                     } else {
                                         woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                                         echo $message;
                                         woocommerce_get_template('emails/email-footer.php');
                                     }
                                     $woo_temp_msg = ob_get_clean();
                                 } else {
                                     $woo_temp_msg = $message;
                                 }
                                 $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)) {
                                             // wp_mail($to, $subject, $message);
                                             $store_template_id = array($emails->id);
                                             $store_template_id = maybe_serialize($store_template_id);
                                             $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                                             //add to mail log
                                             $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)) {
                                             // wp_mail($to, $subject, $message);
                                             $store_template_id = array($emails->id);
                                             $store_template_id = maybe_serialize($store_template_id);
                                             $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                                             //add to mail log
                                             $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());
                                     $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'old_order' => '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_' . $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);
                                     }
                                     //  $user = get_userdata($each_cart->user_id); NOT APPLICABLE
                                     $order_object = maybe_unserialize($each_cart->cart_details);
                                     $to = $order_object->billing_email;
                                     $user_lang = $each_cart->wpml_lang;
                                     $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;
                                     $message = fp_get_wpml_text('rac_template_' . $emails->id . '_message', $each_cart->wpml_lang, $emails->message);
                                     $message = str_replace('{rac.cartlink}', $url_to_click, $message);
                                     $subject = RecoverAbandonCart::shortcode_in_subject($firstname, $lastname, $subject);
                                     $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, $each_cart->cart_abandon_time);
                                         $message = str_replace('{rac.coupon}', $coupon_code, $message);
                                         //replacing shortcode with coupon code
                                     }
                                     add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                                     $message = do_shortcode($message);
                                     //shortcode feature
                                     if (get_option('rac_email_use_temp_plain') != 'yes') {
                                         ob_start();
                                         if (function_exists('wc_get_template')) {
                                             wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                                             echo $message;
                                             wc_get_template('emails/email-footer.php');
                                         } else {
                                             woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                                             echo $message;
                                             woocommerce_get_template('emails/email-footer.php');
                                         }
                                         $woo_temp_msg = ob_get_clean();
                                     } else {
                                         $woo_temp_msg = $message;
                                     }
                                     $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)) {
                                                 // wp_mail($to, $subject, $message);
                                                 $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));
                                                 //add to mail log
                                                 $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)) {
                                                 // wp_mail($to, $subject, $message);
                                                 $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));
                                                 //add to mail log
                                                 $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();
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (get_option('rac_email_use_guests') == 'yes') {
                     /*  $tablecheckproduct .= "It is from Guest2 Object";
                         $dump = print_r($cart_array, true);
                         $tablecheckproduct .= $dump; */
                     //  if ($order->user_id == '') {
                     foreach ($order->get_items() as $products) {
                         if ((double) $woocommerce->version <= (double) '2.0.20') {
                             $objectproduct = get_product($products['product_id']);
                             $objectproductvariable = get_product($products['variation_id']);
                         } else {
                             $objectproduct = new WC_Product($products['product_id']);
                             $objectproductvariable = new WC_Product_Variable($products['variation_id']);
                         }
                         $tablecheckproduct .= "<tr>";
                         if (get_option('rac_hide_product_name_product_info_shortcode') != 'yes') {
                             $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_title($products['product_id']) . "</td>";
                         }
                         if (get_option('rac_hide_product_image_product_info_shortcode') != 'yes') {
                             $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . get_the_post_thumbnail($products['product_id'], array(90, 90)) . "</td>";
                         }
                         if (get_option('rac_hide_product_price_product_info_shortcode') != 'yes') {
                             $tablecheckproduct .= "<td style='text-align:left;vertical-align:middle;border:1px solid #eee;word-wrap:break-word;padding:12px'>" . self::get_rac_formatprice($products['variation_id'] == '' ? $objectproduct->get_price() : $objectproductvariable->get_price()) . "</td>";
                         }
                         $tablecheckproduct .= "</tr>";
                     }
                     // }
                     $tablecheckproduct .= "</table>";
                     //guest mail
                     if ($emails->status == "ACTIVE") {
                         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());
                                 $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'old_order' => '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_' . $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);
                                 }
                                 //  $user = get_userdata($each_cart->user_id); NOT APPLICABLE
                                 $order_object = maybe_unserialize($each_cart->cart_details);
                                 $to = $order_object->billing_email;
                                 $user_lang = $each_cart->wpml_lang;
                                 $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;
                                 $message = fp_get_wpml_text('rac_template_' . $emails->id . '_message', $each_cart->wpml_lang, $emails->message);
                                 $message = str_replace('{rac.cartlink}', $url_to_click, $message);
                                 $subject = RecoverAbandonCart::shortcode_in_subject($firstname, $lastname, $subject);
                                 $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, $each_cart->cart_abandon_time);
                                     $message = str_replace('{rac.coupon}', $coupon_code, $message);
                                     //replacing shortcode with coupon code
                                 }
                                 add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                                 $message = do_shortcode($message);
                                 //shortcode feature
                                 if (get_option('rac_email_use_temp_plain') != 'yes') {
                                     ob_start();
                                     if (function_exists('wc_get_template')) {
                                         wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                                         echo $message;
                                         wc_get_template('emails/email-footer.php');
                                     } else {
                                         woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                                         echo $message;
                                         woocommerce_get_template('emails/email-footer.php');
                                     }
                                     $woo_temp_msg = ob_get_clean();
                                 } else {
                                     $woo_temp_msg = $message;
                                 }
                                 $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)) {
                                             // wp_mail($to, $subject, $message);
                                             $store_template_id = array($emails->id);
                                             $store_template_id = maybe_serialize($store_template_id);
                                             $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                                             //add to mail log
                                             $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)) {
                                             // wp_mail($to, $subject, $message);
                                             $store_template_id = array($emails->id);
                                             $store_template_id = maybe_serialize($store_template_id);
                                             $wpdb->update($abandancart_table_name, array('mail_template_id' => $store_template_id), array('id' => $each_cart->id));
                                             //add to mail log
                                             $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());
                                     $url_to_click = esc_url_raw(add_query_arg(array('abandon_cart' => $each_cart->id, 'email_template' => $emails->id, 'old_order' => '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_' . $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);
                                     }
                                     //  $user = get_userdata($each_cart->user_id); NOT APPLICABLE
                                     $order_object = maybe_unserialize($each_cart->cart_details);
                                     $to = $order_object->billing_email;
                                     $user_lang = $each_cart->wpml_lang;
                                     $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;
                                     $message = fp_get_wpml_text('rac_template_' . $emails->id . '_message', $each_cart->wpml_lang, $emails->message);
                                     $message = str_replace('{rac.cartlink}', $url_to_click, $message);
                                     $subject = RecoverAbandonCart::shortcode_in_subject($firstname, $lastname, $subject);
                                     $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, $each_cart->cart_abandon_time);
                                         $message = str_replace('{rac.coupon}', $coupon_code, $message);
                                         //replacing shortcode with coupon code
                                     }
                                     add_filter('woocommerce_email_footer_text', array('RecoverAbandonCart', 'rac_footer_email_customization'));
                                     $message = do_shortcode($message);
                                     //shortcode feature
                                     if (get_option('rac_email_use_temp_plain') != 'yes') {
                                         ob_start();
                                         if (function_exists('wc_get_template')) {
                                             wc_get_template('emails/email-header.php', array('email_heading' => $subject));
                                             echo $message;
                                             wc_get_template('emails/email-footer.php');
                                         } else {
                                             woocommerce_get_template('emails/email-header.php', array('email_heading' => $subject));
                                             echo $message;
                                             woocommerce_get_template('emails/email-footer.php');
                                         }
                                         $woo_temp_msg = ob_get_clean();
                                     } else {
                                         $woo_temp_msg = $message;
                                     }
                                     $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)) {
                                                 // wp_mail($to, $subject, $message);
                                                 $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));
                                                 //add to mail log
                                                 $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)) {
                                                 // wp_mail($to, $subject, $message);
                                                 $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));
                                                 //add to mail log
                                                 $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 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();
                         }
                     }
                 }
             }
         }
     }
 }
        function list_order_item_addresses($order_id)
        {
            global $woocommerce;
            if (false == apply_filters('wcms_list_order_item_addresses', true, $order_id)) {
                return;
            }
            if ($order_id instanceof WC_Order) {
                $order = $order_id;
                $order_id = $order->id;
            } else {
                $order = WC_MS_Compatibility::wc_get_order($order_id);
            }
            $methods = get_post_meta($order_id, '_shipping_methods', true);
            $shipping_methods = $order->get_shipping_methods();
            $packages = get_post_meta($order_id, '_wcms_packages', true);
            $multiship = get_post_meta($order_id, '_multiple_shipping', true);
            if (!$packages || count($packages) == 1) {
                return;
            }
            // load the address fields
            $this->load_cart_files();
            $cart = new WC_Cart();
            echo '<p><strong>' . __('This order ships to multiple addresses.', 'wc_shipping_multiple_address') . '</strong></p>';
            echo '<table class="shop_table shipping_packages" cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">';
            echo '<thead><tr>';
            echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Products', 'woocommerce') . '</th>';
            echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Address', 'woocommerce') . '</th>';
            echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Notes', 'woocommerce') . '</th>';
            echo '</tr></thead><tbody>';
            foreach ($packages as $x => $package) {
                $products = $package['contents'];
                $method = $methods[$x]['label'];
                foreach ($shipping_methods as $ship_method) {
                    if ($ship_method['method_id'] == $method) {
                        $method = $ship_method['name'];
                        break;
                    }
                }
                $address = '';
                if (!empty($package['full_address'])) {
                    $address = wcms_get_formatted_address($package['full_address']);
                }
                ?>
                <tr>
                    <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><ul>
                    <?php 
                foreach ($products as $i => $product) {
                    ?>
                        <li><?php 
                    echo get_the_title($product['data']->id) . ' &times; ' . $product['quantity'] . '<br />' . $cart->get_item_data($product, true);
                    ?>
</li>
                    <?php 
                }
                ?>
                    </ul></td>
                    <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">
                        <?php 
                echo $address;
                ?>
                        <br/>
                        <em>(<?php 
                echo $method;
                ?>
)</em>
                    </td>
                    <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">
                        <?php 
                if (!empty($package['note'])) {
                    echo $package['note'];
                } else {
                    echo '&ndash;';
                }
                if (!empty($package['date'])) {
                    echo '<p>' . sprintf(__('Delivery date: %s', 'wc_shipping_multiple_address'), $package['date']) . '</p>';
                }
                ?>
                    </td>
                </tr>
                <?php 
            }
            echo '</table>';
        }
 function get_proceed_link($parameter)
 {
     $id = $parameter['id'];
     $wc = new WC_Cart();
     return add_query_arg(array('add-to-cart' => $id), $wc->get_checkout_url());
 }
 /**
  *
  */
 public function filter_woocommerce_add_to_cart_validation($valid, $product_id, $quantity, $variation_id = '', $variations = '')
 {
     global $woocommerce;
     $product = wc_get_product($product_id);
     if ($product->product_type === "variable") {
         $deductornot = get_post_meta($variation_id, '_deductornot', true);
         $deductamount = get_post_meta($variation_id, '_deductamount', true);
         $getvarclass = new WC_Product_Variation($variation_id);
         //reset($array);
         $aatrs = $getvarclass->get_variation_attributes();
         foreach ($aatrs as $key => $value) {
             $slug = $value;
             $cat = str_replace('attribute_', '', $key);
         }
         $titlevaria = get_term_by('slug', $slug, $cat);
         $backorder = get_post_meta($product->post->ID, '_backorders', true);
         $string = WC_Cart::get_item_data($cart_item, $flat);
         //var_dump($string);
         if ($backorder == 'no') {
             if ($deductornot == "yes") {
                 $currentstock = $product->get_stock_quantity();
                 $reduceamount = intval($quantity) * intval($deductamount);
                 $currentavail = intval($currentstock / $deductamount);
                 if ($reduceamount > $currentstock) {
                     $valid = false;
                     wc_add_notice('' . __('You that goes over our availble stock amount.', 'woocommerce') . __('We have: ', 'woocommerce') . $currentavail . ' ' . $product->post->post_title . ' ' . $titlevaria->name . '\'s ' . __(' available.', 'woocommerce'), 'error');
                     return $valid;
                 } else {
                     $valid = true;
                     return $valid;
                 }
             } else {
                 return true;
             }
         }
     }
     return true;
 }
Example #20
0
function ajax_add_all_cart()
{
    $id = $_POST['id'];
    $id_arr = explode(',', $id);
    unset($id_arr[0]);
    $cart_ajax = new WC_Cart();
    foreach ($id_arr as $id_arr) {
        $cart_ajax->add_to_cart($id_arr);
    }
    echo 'Sản phẩm của bạn đã được thêm vào giỏ thành công <a href="' . WC()->cart->get_cart_url() . '">Xem giỏ hàng</a>';
    die("");
}