New Function for Cart Total (Pre-tax and Pre-Shipping)

Hi,

I have created a new function in my template-functions.php file to show the value of items in the cart pre-tax and pre-shipping.

//Prints cart total - pre-tax and pre-shipping, Mark O'Leary
function mp_cart_total($echo = false) {
global $mp, $blog_id;
$blog_id = (is_multisite()) ? $blog_id : 1;
$settings = get_option('mp_settings');
$current_blog_id = $blog_id;

$global_cart = $mp->get_cart_contents(true);
if (!$mp->global_cart) //get subset if needed
$selected_cart[$blog_id] = $global_cart[$blog_id];
else
$selected_cart = $global_cart;

$totals = array();
//$shipping_prices = array();
//$tax_prices = array();
foreach ($selected_cart as $bid => $cart) {
if (is_multisite())
switch_to_blog($bid);

foreach ($cart as $product_id => $variations) {
foreach ($variations as $variation => $data) {
$totals[] = $data['price'] * $data['quantity'];
}
}
}
$total = array_sum($totals);
return $total;
}

To use just call mp_cart_total() or echo mp_cart_total()