function submit_to_paypal()
{
    $eStore_default_currency = get_option('cart_payment_currency');
    $eStore_return_url = get_option('cart_return_from_paypal_url');
    $eStore_sandbox_enabled = get_option('eStore_cart_enable_sandbox');
    if (!empty($eStore_default_currency)) {
        $paypal_currency = $eStore_default_currency;
    } else {
        $paypal_currency = 'USD';
    }
    $email = get_option('cart_paypal_email');
    $myPaypal = new Paypal();
    $myPaypal->gatewayUrl = 'https://www.paypal.com/cgi-bin/webscr';
    //PAYPAL_LIVE_URL
    $myPaypal->addField('charset', "utf-8");
    $myPaypal->addField('business', $email);
    $paypal_currency = apply_filters('eStore_change_curr_code_before_payment_filter', $paypal_currency);
    $myPaypal->addField('currency_code', $paypal_currency);
    $cancel_url = get_option('cart_cancel_from_paypal_url');
    if (!empty($cancel_url)) {
        $myPaypal->addField('cancel_return', $cancel_url);
    }
    if (get_option('eStore_auto_product_delivery') != '') {
        if (WP_ESTORE_ENABLE_NEW_CHECKOUT_REDIRECTION === '1') {
            $notify = WP_ESTORE_SITE_HOME_URL . '/?estore_pp_ipn=process';
        } else {
            $notify = WP_ESTORE_URL . '/paypal.php';
        }
        $myPaypal->addField('notify_url', $notify);
    }
    // =======================
    global $wpdb;
    $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
    $weight = 0;
    $count = 1;
    $all_items_digital = true;
    foreach ($_SESSION['eStore_cart'] as $item) {
        $rounded_price = round($item['price'], 2);
        $rounded_price = apply_filters('eStore_change_price_before_payment_filter', $rounded_price);
        $myPaypal->addField("item_name_{$count}", htmlspecialchars($item['name']));
        $myPaypal->addField("amount_{$count}", $rounded_price);
        $myPaypal->addField("quantity_{$count}", $item['quantity']);
        $myPaypal->addField("item_number_{$count}", $item['item_number']);
        //Check to see if this is a tax free item and set the tax accordingly so that the profile based PayPal tax can work nicely
        if ($item['tax'] == "0") {
            $myPaypal->addField("tax_{$count}", $item['tax']);
        }
        $id = $item['item_number'];
        $ret_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$id}'", OBJECT);
        if (!empty($ret_product->weight)) {
            $weight += $ret_product->weight * $item['quantity'];
        }
        if (empty($item['digital_flag'])) {
            $all_items_digital = false;
        }
        $count++;
    }
    $total_items_in_cart = count($_SESSION['eStore_cart']);
    if ($total_items_in_cart == 1 && !empty($ret_product->return_url)) {
        $myPaypal->addField('return', $ret_product->return_url);
    } else {
        if (!empty($eStore_return_url)) {
            $myPaypal->addField('return', $eStore_return_url);
        }
    }
    if (!get_option('eStore_paypal_profile_shipping')) {
        //Not Using paypal's profile based shipping so include shipping otherwise ignore shipping here as it will be calculated on paypal's site
        $shipping = round($_SESSION['eStore_cart_postage_cost'], 2);
        if (!empty($shipping)) {
            $shipping = apply_filters('eStore_change_shipping_before_payment_filter', $shipping);
            //change tax amount before submitting if converting currency to another type
            $myPaypal->addField('no_shipping', '2');
            $myPaypal->addField('handling_cart', $shipping);
            //$myPaypal->addField('shipping_1', $shipping);
        } else {
            //If you do not want to collect address for checkout that has no shipping cost then uncomment the following line of code.
            //$myPaypal->addField('no_shipping', '1');
        }
    } else {
        //Include the weight for profile based shipping calc
        $myPaypal->addField('weight_cart', round($weight, 2));
        $myPaypal->addField('weight_unit', 'lbs');
        if ($all_items_digital) {
            //All the items in the cart are digital items so set the shipping flag to 0 so no shipping is charged
            $total_items = count($_SESSION['eStore_cart']);
            for ($i = 1; $i <= $total_items; $i++) {
                $myPaypal->addField('shipping_' . $i, '0');
            }
        } else {
            if (isset($_SESSION['eStore_cart_postage_cost']) && $_SESSION['eStore_cart_postage_cost'] == 0) {
                //Free shipping discount applied. send 0 shipping to override profile based shipping
                if (empty($weight)) {
                    //Add $0 shipping override
                    $myPaypal->addField('shipping_1', '0');
                }
            }
        }
    }
    if (!empty($_SESSION['eStore_cart_total_tax'])) {
        $cart_total_tax = round($_SESSION['eStore_cart_total_tax'], 2);
        $cart_total_tax = apply_filters('eStore_change_tax_before_payment_filter', $cart_total_tax);
        //change tax amount before submitting if converting currency to another type
        $myPaypal->addField('tax_cart', $cart_total_tax);
    }
    if (get_option('eStore_display_tx_result')) {
        $myPaypal->addField('rm', '1');
    }
    if (defined('WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE') && WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE !== '0') {
        //Set the country/region preference by force.
        $myPaypal->addField('lc', WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE);
    }
    $myPaypal->addField('cmd', '_cart');
    $myPaypal->addField('upload', '1');
    $custom_field_val = eStore_get_custom_field_value();
    $myPaypal->addField('custom', $custom_field_val);
    $myPaypal->addField('mrb', '3FWGC6LFTMTUG');
    $page_style_name = get_option('eStore_paypal_co_page_style');
    if (!empty($page_style_name)) {
        $myPaypal->addField('page_style', $page_style_name);
    }
    $returnButtonText = get_option('eStore_paypal_return_button_text');
    if (!empty($returnButtonText)) {
        $myPaypal->addField('cbt', $returnButtonText);
    }
    // Enable sandbox mode if needed
    if ($eStore_sandbox_enabled) {
        $myPaypal->enableTestMode();
    }
    // Lets clear the cart if automatic redirection is not being used otherwise we will empty the cart after the redirection
    $PDT_auth_token = get_option('eStore_paypal_pdt_token');
    if (empty($PDT_auth_token)) {
        reset_eStore_cart();
    }
    // submit the payment!
    $myPaypal->submitPayment2(WP_ESTORE_CLICK_HERE);
}