function wpspc_cart_actions_handler()
{
    unset($_SESSION['wpspsc_cart_action_msg']);
    if (isset($_POST['addcart'])) {
        setcookie("cart_in_use", "true", time() + 21600, "/", COOKIE_DOMAIN);
        //useful to not serve cached page when using with a caching plugin
        if (function_exists('wp_cache_serve_cache_file')) {
            //WP Super cache workaround
            setcookie("comment_author_", "wp_cart", time() + 21600, "/", COOKIE_DOMAIN);
        }
        //sanitize data
        $_POST['wspsc_product'] = strip_tags($_POST['wspsc_product']);
        //for PHP5.2 use filter_var($_POST['wspsc_product'], FILTER_SANITIZE_STRING);
        $_POST['item_number'] = strip_tags($_POST['item_number']);
        if (isset($_POST['price'])) {
            $_POST['price'] = strip_tags($_POST['price']);
            //Validate price
            $hash_once_p = strip_tags($_POST['hash_one']);
            $p_key = get_option('wspsc_private_key_one');
            $hash_one_cm = md5($p_key . '|' . $_POST['price']);
            if ($hash_once_p != $hash_one_cm) {
                //Validation failed
                wp_die('Error! The price validation failed.');
            }
        }
        isset($_POST['shipping']) ? $_POST['shipping'] = strip_tags($_POST['shipping']) : ($_POST['shipping'] = '');
        isset($_POST['cartLink']) ? $_POST['cartLink'] = strip_tags($_POST['cartLink']) : ($_POST['cartLink'] = '');
        isset($_POST['stamp_pdf']) ? $_POST['stamp_pdf'] = strip_tags($_POST['stamp_pdf']) : ($_POST['stamp_pdf'] = '');
        $count = 1;
        $products = array();
        if (isset($_SESSION['simpleCart'])) {
            $products = $_SESSION['simpleCart'];
            if (is_array($products)) {
                foreach ($products as $key => $item) {
                    if ($item['name'] == stripslashes($_POST['wspsc_product'])) {
                        $count += $item['quantity'];
                        $item['quantity']++;
                        unset($products[$key]);
                        array_push($products, $item);
                    }
                }
            } else {
                $products = array();
            }
        }
        if ($count == 1) {
            if (!empty($_POST[$_POST['wspsc_product']])) {
                $price = $_POST[$_POST['wspsc_product']];
            } else {
                $price = $_POST['price'];
            }
            $default_cur_symbol = get_option('cart_currency_symbol');
            $price = str_replace($default_cur_symbol, "", $price);
            $shipping = $_POST['shipping'];
            $shipping = str_replace($default_cur_symbol, "", $shipping);
            $product = array('name' => stripslashes($_POST['wspsc_product']), 'price' => $price, 'price_orig' => $price, 'quantity' => $count, 'shipping' => $shipping, 'cartLink' => $_POST['cartLink'], 'item_number' => $_POST['item_number']);
            if (isset($_POST['file_url']) && !empty($_POST['file_url'])) {
                $file_url = strip_tags($_POST['file_url']);
                $product['file_url'] = $file_url;
            }
            if (isset($_POST['thumbnail']) && !empty($_POST['thumbnail'])) {
                $thumbnail = strip_tags($_POST['thumbnail']);
                $product['thumbnail'] = $thumbnail;
            }
            if (isset($_POST['stamp_pdf']) && !empty($_POST['stamp_pdf'])) {
                $stamp_pdf = strip_tags($_POST['stamp_pdf']);
                $product['stamp_pdf'] = $stamp_pdf;
            }
            array_push($products, $product);
        }
        sort($products);
        $_SESSION['simpleCart'] = $products;
        wpspsc_reapply_discount_coupon_if_needed();
        //Re-apply coupon to the cart if necessary
        if (!isset($_SESSION['simple_cart_id']) && empty($_SESSION['simple_cart_id'])) {
            wpspc_insert_new_record();
        } else {
            //cart updating
            if (isset($_SESSION['simple_cart_id']) && !empty($_SESSION['simple_cart_id'])) {
                wpspc_update_cart_items_record();
            } else {
                echo "<p>" . __("Error! Your session is out of sync. Please reset your session.", "wordpress-simple-paypal-shopping-cart") . "</p>";
            }
        }
        if (get_option('wp_shopping_cart_auto_redirect_to_checkout_page')) {
            $checkout_url = get_option('cart_checkout_page_url');
            if (empty($checkout_url)) {
                echo "<br /><strong>" . __("Shopping Cart Configuration Error! You must specify a value in the 'Checkout Page URL' field for the automatic redirection feature to work!", "wordpress-simple-paypal-shopping-cart") . "</strong><br />";
            } else {
                $redirection_parameter = 'Location: ' . $checkout_url;
                header($redirection_parameter);
                exit;
            }
        }
    } else {
        if (isset($_POST['cquantity'])) {
            $products = $_SESSION['simpleCart'];
            foreach ($products as $key => $item) {
                if (stripslashes($item['name']) == stripslashes($_POST['wspsc_product']) && $_POST['quantity']) {
                    $item['quantity'] = $_POST['quantity'];
                    unset($products[$key]);
                    array_push($products, $item);
                } else {
                    if ($item['name'] == stripslashes($_POST['wspsc_product']) && !$_POST['quantity']) {
                        unset($products[$key]);
                    }
                }
            }
            sort($products);
            $_SESSION['simpleCart'] = $products;
            wpspsc_reapply_discount_coupon_if_needed();
            //Re-apply coupon to the cart if necessary
            if (isset($_SESSION['simple_cart_id']) && !empty($_SESSION['simple_cart_id'])) {
                wpspc_update_cart_items_record();
            }
        } else {
            if (isset($_POST['delcart'])) {
                $products = $_SESSION['simpleCart'];
                foreach ($products as $key => $item) {
                    if ($item['name'] == stripslashes($_POST['wspsc_product'])) {
                        unset($products[$key]);
                    }
                }
                $_SESSION['simpleCart'] = $products;
                wpspsc_reapply_discount_coupon_if_needed();
                //Re-apply coupon to the cart if necessary
                if (isset($_SESSION['simple_cart_id']) && !empty($_SESSION['simple_cart_id'])) {
                    wpspc_update_cart_items_record();
                }
                if (count($_SESSION['simpleCart']) < 1) {
                    reset_wp_cart();
                }
            } else {
                if (isset($_POST['wpspsc_coupon_code'])) {
                    $coupon_code = strip_tags($_POST['wpspsc_coupon_code']);
                    wpspsc_apply_cart_discount($coupon_code);
                    if (isset($_SESSION['simple_cart_id']) && !empty($_SESSION['simple_cart_id'])) {
                        wpspc_update_cart_items_record();
                    }
                }
            }
        }
    }
}
    }
    return $content;
}
// Reset the Cart as this is a returned customer from Paypal
if (isset($_GET["merchant_return_link"]) && !empty($_GET["merchant_return_link"])) {
    reset_wp_cart();
    header('Location: ' . get_option('cart_return_from_paypal_url'));
}
if (isset($_GET["mc_gross"]) && $_GET["mc_gross"] > 0) {
    reset_wp_cart();
    header('Location: ' . get_option('cart_return_from_paypal_url'));
}
//Clear the cart if the customer landed on the thank you page
if (get_option('wp_shopping_cart_reset_after_redirection_to_return_page')) {
    if (get_option('cart_return_from_paypal_url') == cart_current_page_url()) {
        reset_wp_cart();
    }
}
function reset_wp_cart()
{
    $products = $_SESSION['simpleCart'];
    if (empty($products)) {
        unset($_SESSION['simpleCart']);
        return;
    }
    foreach ($products as $key => $item) {
        unset($products[$key]);
    }
    $_SESSION['simpleCart'] = $products;
}
if (isset($_POST['addcart'])) {