function wpmp_update_shipping() { if ($_REQUEST['update_shipping'] == "update") { $cart_data = wpmp_get_cart_data(); $cart_data['shipping']['shipping_method'] = $_POST['shipping_method']; $cart_data['shipping']['shipping_rate'] = $_POST['shipping_rate']; wpmp_update_cart_data($cart_data); die; } }
function wpmp_calculate_discount() { //echo "I'm here "; global $current_user; get_currentuserinfo(); $role = $current_user->roles[0]; $role = $role ? $role : 'guest'; $discount_r = 0; $cart_items = wpmp_get_cart_items(); $total = 0; if (is_array($cart_items)) { //$lprices = array(); foreach ($cart_items as $pid => $item) { $cart_items[$pid]['ID'] = $pid; $cart_items[$pid]['post_title'] = get_the_title($pid); $prices = 0; $variations = ""; $svariation = array(); $lvariation = array(); $lvariations = array(); $lprices = array(); $opt = get_post_meta($pid, "wpmp_list_opts", true); @extract($opt); foreach ($variation as $key => $value) { foreach ($value as $optionkey => $optionvalue) { if ($optionkey != "vname" && $optionkey != 'multiple') { if (isset($item['multi']) && $item['multi'] == 1) { foreach ($item['item'] as $a => $b) { //different variations, $b is single variation contain variation and quantity if ($b['variation']) { //$lprices[$a] = 0; foreach ($b['variation'] as $c) { if ($c == $optionkey) { $lprices[$a] += $optionvalue['option_price']; $lvariation[$a][] = $optionvalue['option_name'] . ": " . ($optionvalue['option_price'] > 0 ? '+' : '') . $currency_sign . number_format(doubleval($optionvalue['option_price']), 2, ".", ""); } } } } } else { if (isset($item['variation'])) { foreach ($item['variation'] as $var) { if ($var == $optionkey) { $prices += $optionvalue['option_price']; $svariation[] = $optionvalue['option_name'] . ": " . ($optionvalue['option_price'] > 0 ? '+' : '') . $currency_sign . number_format(doubleval($optionvalue['option_price']), 2, ".", ""); } } } } } } } if (trim($item['coupon']) != '') { $valid_coupon = check_coupon($pid, $item['coupon']); } else { $valid_coupon = false; } //echo $valid_coupon . ' :D '; if (!isset($item['multi'])) { $cart_items[$pid]['prices'] = $prices; $cart_items[$pid]['variations'] = $svariation; if (is_numeric($valid_coupon) && $valid_coupon != false) { $cart_items[$pid]['coupon_amount'] = ($item['price'] + $prices) * $item['quantity'] * $valid_coupon / 100; $cart_items[$pid]['discount_amount'] = (($item['price'] + $prices) * $item['quantity'] - $cart_items[$pid]['coupon_amount']) * $opt['discount'][$role] / 100; } else { $cart_items[$pid]['discount_amount'] = ($item['price'] + $prices) * $item['quantity'] * $opt['discount'][$role] / 100; } if ($valid_coupon == false) { $cart_items[$pid]['error'] = "No Valid Coupon Found"; } else { unset($cart_items[$pid]['error']); } } elseif (isset($item['multi']) && $item['multi'] == 1) { foreach ($lprices as $key => $value) { $cart_items[$pid]['item'][$key]['prices'] = $value; $cart_items[$pid]['item'][$key]['variations'] = $lvariation[$key]; if ($valid_coupon != 0) { $cart_items[$pid]['item'][$key]['coupon_amount'] = ($item['price'] + $value) * $item['item'][$key]['quantity'] * $valid_coupon / 100; $cart_items[$pid]['item'][$key]['discount_amount'] = (($item['price'] + $value) * $item['item'][$key]['quantity'] - $cart_items[$pid]['item'][$key]['coupon_amount']) * $opt['discount'][$role] / 100; } else { $cart_items[$pid]['item'][$key]['discount_amount'] = ($item['price'] + $value) * $item['item'][$key]['quantity'] * $opt['discount'][$role] / 100; } if ($valid_coupon == false) { $cart_items[$pid]['item'][$key]['error'] = "No Valid Coupon Found"; } } } // } wpmp_update_cart_data($cart_items); } }