foreach ($stateList as $code => $value) { $eshopstatelist[$value['id']] = $value['code']; } foreach ($_POST as $name => $value) { //have to do a discount code check here - otherwise things just don't work - but fine for free shipping codes if (strstr($name, 'amount_')) { if (isset($_SESSION['eshop_discount' . $blog_id]) && eshop_discount_codes_check()) { $chkcode = valid_eshop_discount_code($_SESSION['eshop_discount' . $blog_id]); if ($chkcode && apply_eshop_discount_code('discount') > 0) { $discount = apply_eshop_discount_code('discount') / 100; $value = number_format(round($value - $value * $discount, 2), 2); $vset = 'yes'; } } if (is_discountable(calculate_total()) != 0 && !isset($vset)) { $discount = is_discountable(calculate_total()) / 100; $value = number_format(round($value - $value * $discount, 2), 2); } } if (sizeof($stateList) > 0 && ($name == 'state' || $name == 'ship_state')) { if ($value != '') { $value = $eshopstatelist[$value]; } } $p->add_field($name, $value); } // $p->add_field('return_method','2'); //1=GET 2=POST // was return method now rm - go figure. $p->add_field('rm', '2'); //1=GET 2=POST //settings in paypal/index.php to change these
function eshop_checkout($espost) { $espost = stripslashes_deep($espost); global $blog_id, $eshopoptions, $wpdb; $contineproceed = '1'; //cache eshop_cache(); $echoit = ''; include_once ABSPATH . 'wp-includes/wp-db.php'; include_once WP_PLUGIN_DIR . "/eshop/cart-functions.php"; if (isset($espost['eshop_payment'])) { $_SESSION['eshop_payment' . $blog_id] = preg_replace('/[^a-zA-Z0-9\\-_]/', '', $espost['eshop_payment']); } if (!isset($_SESSION['eshop_payment' . $blog_id])) { $paymentmethod = 'paypal'; } else { $paymentmethod = $_SESSION['eshop_payment' . $blog_id]; } //left over from previous script, leaving in just in case another payment method is used. $chkerror = 0; $numberofproducts = 0; //filter for plugin merchant gateways $eshopmgincpath = apply_filters('eshop_mg_inc_path', WP_PLUGIN_DIR . '/eshop/' . $paymentmethod . '.php', $paymentmethod); // if everything went ok do the following, hopefully the rest won't happen! if (isset($_GET['eshopaction'])) { if ($_GET['eshopaction'] == 'success') { include_once $eshopmgincpath; } } //filter for plugin merchant gateways $eshopmgincidxpath = apply_filters('eshop_mg_inc_idx_path', WP_PLUGIN_DIR . '/eshop/' . $paymentmethod . '/index.php', $paymentmethod); if (file_exists($eshopmgincidxpath)) { include_once $eshopmgincidxpath; } if (isset($_SESSION['eshopcart' . $blog_id])) { $shopcart = $_SESSION['eshopcart' . $blog_id]; $numberofproducts = sizeof($_SESSION['eshopcart' . $blog_id]); /* unused code? $productsandqty=''; while (list ($product, $amount) = each ($_SESSION['eshopcart'.$blog_id])){ $productsandqty.=" $product-$amount"; $productsandqty=trim($productsandqty); } */ $keys = array_keys($_SESSION['eshopcart' . $blog_id]); $productidkeys = implode(",", $keys); $productidkeys = trim($productidkeys); //reqd for shipping - finds the correct state for working out shipping, and set things up for later usage. if (isset($espost['ship_name'])) { if ($espost['ship_name'] != '' || $espost['ship_address'] != '' || $espost['ship_city'] != '' || $espost['ship_postcode'] != '' || $espost['ship_company'] != '' || $espost['ship_phone'] != '' || $espost['ship_country'] != '' || $espost['ship_state'] != '') { if ($espost['ship_name'] == '') { $espost['ship_name'] = $espost['first_name'] . " " . $espost['last_name']; } if ($espost['ship_company'] == '') { $espost['ship_company'] = $espost['company']; } if ($espost['ship_phone'] == '') { $espost['ship_phone'] = $espost['phone']; } if ($espost['ship_address'] == '') { $espost['ship_address'] = $espost['address1']; if ($espost['address2'] != '') { $espost['ship_address'] .= ", " . $espost['address2']; } } if ($espost['ship_city'] == '') { $espost['ship_city'] = $espost['city']; } if ($espost['ship_postcode'] == '') { $espost['ship_postcode'] = $espost['zip']; } if ($espost['ship_country'] == '') { $espost['ship_country'] = $espost['country']; } if ($espost['ship_state'] == '') { $espost['ship_state'] = $espost['state']; } if ($espost['ship_altstate'] == '') { $espost['ship_altstate'] = $espost['altstate']; } } else { $espost['ship_name'] = $espost['first_name'] . " " . $espost['last_name']; $espost['ship_company'] = $espost['company']; $espost['ship_phone'] = $espost['phone']; if ($espost['ship_address'] == '') { $espost['ship_address'] = $espost['address1']; if ($espost['address2'] != '') { $espost['ship_address'] .= ", " . $espost['address2']; } } $espost['ship_city'] = $espost['city']; $espost['ship_postcode'] = $espost['zip']; $espost['ship_country'] = $espost['country']; $espost['ship_state'] = $espost['state']; $espost['ship_altstate'] = $espost['altstate']; } $tablecountries = $wpdb->prefix . 'eshop_countries'; $tablestates = $wpdb->prefix . 'eshop_states'; $shippingzone = $eshopoptions['shipping_zone']; if (isset($espost['eshop_shiptype']) && $espost['eshop_shiptype'] != '0') { $sztype = $espost['eshop_shiptype']; $shippingzone = $wpdb->get_var("SELECT area FROM " . $wpdb->prefix . "eshop_rates WHERE rate_type='ship_weight' && class='{$sztype}' LIMIT 1"); } $pzoneid = ''; //$eshopoptions['unknown_state']; if ($shippingzone == 'country') { if (isset($espost['ship_country']) && $espost['ship_country'] != '') { $pzoneid = $espost['ship_country']; } elseif (isset($espost['country']) && $espost['country'] != '') { $pzoneid = $espost['country']; } $pzone = $wpdb->get_var("SELECT zone FROM {$tablecountries} WHERE code='{$pzoneid}' LIMIT 1"); } else { if (isset($espost['state']) && $espost['state'] != '') { $pzoneid = $espost['state']; } if (isset($espost['ship_state']) && $espost['ship_state'] != '') { $pzoneid = $espost['ship_state']; } $pzone = $wpdb->get_var("SELECT zone FROM {$tablestates} WHERE id='{$pzoneid}' LIMIT 1"); if (isset($espost['altstate']) && $espost['altstate'] != '') { $pzone = $eshopoptions['unknown_state']; } if (isset($espost['ship_altstate']) && $espost['ship_altstate'] != '') { $pzone = $eshopoptions['unknown_state']; } } $_SESSION['shiptocountry' . $blog_id] = $eshopoptions['location']; if (isset($espost['ship_country']) && $espost['ship_country'] != '') { $_SESSION['shiptocountry' . $blog_id] = $espost['ship_country']; } elseif (isset($espost['country']) && $espost['country'] != '') { $_SESSION['shiptocountry' . $blog_id] = $espost['country']; } } else { $pzoneid = ''; //$eshopoptions['unknown_state']; $tablecountries = $wpdb->prefix . 'eshop_countries'; $tablestates = $wpdb->prefix . 'eshop_states'; $shippingzone = $eshopoptions['shipping_zone']; if (isset($espost['eshop_shiptype'])) { $sztype = $espost['eshop_shiptype']; $shippingzone = $wpdb->get_var("SELECT area FROM " . $wpdb->prefix . "eshop_rates WHERE rate_type='ship_weight' && class='{$sztype}' LIMIT 1"); } if ($shippingzone == 'country') { if (isset($espost['ship_country']) && $espost['ship_country'] != '') { $pzoneid = $espost['ship_country']; } elseif (isset($espost['country']) && $espost['country'] != '') { $pzoneid = $espost['country']; } $pzone = $wpdb->get_var("SELECT zone FROM {$tablecountries} WHERE code='{$pzoneid}' LIMIT 1"); } else { if (isset($espost['ship_state']) && $espost['ship_state'] != '') { $pzoneid = $espost['ship_state']; } if (isset($espost['state']) && $espost['state'] != '') { $pzoneid = $espost['state']; } $pzone = $wpdb->get_var("SELECT zone FROM {$tablestates} WHERE id='{$pzoneid}' LIMIT 1"); if (isset($espost['altstate']) && $espost['altstate'] != '') { $pzone = $eshopoptions['unknown_state']; } if (isset($espost['ship_altstate']) && $espost['ship_altstate'] != '') { $pzone = $eshopoptions['unknown_state']; } } } // $shiparray = array(); $eshopcartarray = $_SESSION['eshopcart' . $blog_id]; foreach ($eshopcartarray as $productid => $opt) { if (is_array($opt)) { switch ($eshopoptions['shipping']) { case '1': //( per quantity of 1, prices reduced for additional items ) for ($i = 1; $i <= $opt['qty']; $i++) { array_push($shiparray, $opt["pclas"]); } break; case '2': //( once per shipping class no matter what quantity is ordered ) if (!in_array($opt["pclas"], $shiparray)) { array_push($shiparray, $opt["pclas"]); } break; case '3': //( one overall charge no matter how many are ordered ) if (!in_array($opt["pclas"], $shiparray)) { if ($opt["pclas"] != 'F') { array_push($shiparray, 'A'); } } break; case '4': //( weight ) if (isset($espost['eshop_shiptype'])) { unset($shiparray); $shiparray = $espost['eshop_shiptype']; } break; } } } //need an extra check if ($eshopoptions['shipping'] == '4' && 'no' == $eshopoptions['downloads_only'] && isset($espost['submit']) && !isset($espost['eshop_shiptype']) && !eshop_only_downloads()) { $pzone = ''; } //need to check the discount codes here as well: if (eshop_discount_codes_check()) { $_SESSION['eshop_discount' . $blog_id] = ''; unset($_SESSION['eshop_discount' . $blog_id]); if (isset($espost['eshop_discount']) && $espost['eshop_discount'] != '') { $chkcode = valid_eshop_discount_code($espost['eshop_discount']); if ($chkcode) { $_SESSION['eshop_discount' . $blog_id] = $espost['eshop_discount']; } } } //show the cart if (isset($_GET['eshopaction']) && $_GET['eshopaction'] != 'redirect' || !isset($_GET['eshopaction'])) { $echoit .= display_cart($_SESSION['eshopcart' . $blog_id], false, $eshopoptions['checkout'], $pzone, $shiparray); } } $error = ''; if (isset($espost['submit'])) { //form handling foreach ($espost as $key => $value) { $key = $value; } //setupshipping arrays $reqdvalues = array('shipping', 'first_name', 'last_name', 'email', 'phone', 'address', 'city', 'zip', 'pay'); if ($eshopoptions['shipping'] != '4') { if ($eshopoptions['shipping_zone'] == 'country') { $reqdvalues[] = 'country'; } else { $reqdvalues[] = 'state'; } } else { $creqd = ''; $dtable = $wpdb->prefix . 'eshop_rates'; $query = $wpdb->get_results("SELECT DISTINCT(area) from {$dtable} where rate_type='ship_weight'"); foreach ($query as $k) { $reqdvalues[] = $k->area; } } $linkattr = apply_filters('eShopCheckoutLinksAttr', ''); $reqdarray = apply_filters('eshopCheckoutReqd', $reqdvalues); if ($eshopoptions['shipping'] == '4' && 'no' == $eshopoptions['downloads_only'] && !isset($espost['eshop_shiptype']) && !eshop_only_downloads()) { $error .= '<li>' . __('<strong>Shipping</strong> - not selected.', 'eshop') . '</li>'; } if (isset($espost['first_name'])) { $valid = checkAlpha($espost['first_name']); if ($valid == FALSE && eshop_checkreqd($reqdarray, 'first_name')) { $error .= '<li>' . __('<strong>First name</strong> - missing or incorrect.', 'eshop') . '</li>'; } } if (isset($espost['last_name'])) { $valid = checkAlpha($espost['last_name']); if ($valid == FALSE && eshop_checkreqd($reqdarray, 'last_name')) { $error .= '<li>' . __('<strong>Last name</strong> - missing or incorrect.', 'eshop') . '</li>'; } } if (isset($espost['email'])) { $valid = checkEmail($espost['email']); if ($valid == FALSE && eshop_checkreqd($reqdarray, 'email')) { $error .= '<li>' . __('<strong>Email address</strong> - missing or incorrect.', 'eshop') . '</li>'; } } if (isset($espost['phone'])) { $valid = checkPhone($espost['phone']); if ($valid == FALSE && eshop_checkreqd($reqdarray, 'phone')) { $error .= '<li>' . __('<strong>Phone Number</strong> - missing or incorrect', 'eshop') . '.</li>'; } } if (isset($espost['address1'])) { $valid = checkAlpha($espost['address1']); if ($valid == FALSE && eshop_checkreqd($reqdarray, 'address')) { $error .= '<li>' . __('<strong>Address</strong> - missing or incorrect.', 'eshop') . '</li>'; } } if (isset($espost['city'])) { $valid = checkAlpha($espost['city']); if ($valid == FALSE && eshop_checkreqd($reqdarray, 'city')) { $error .= '<li>' . __('<strong>City or town</strong> - missing or incorrect.', 'eshop') . '</li>'; } } if (eshop_checkreqd($reqdarray, 'state')) { if (isset($espost['state']) && $espost['state'] == '' && $espost['altstate'] == '') { $error .= '<li>' . __('<strong>State/County/Province</strong> - missing or incorrect.', 'eshop') . '</li>'; } } if (eshop_checkreqd($reqdarray, 'country')) { if (isset($espost['country'])) { $valid = checkAlpha($espost['country']); if ($valid == FALSE) { $error .= '<li>' . __('<strong>Country</strong> - missing or incorrect.', 'eshop') . '</li>'; } } } if (isset($espost['country']) && $espost['country'] == 'US' && $espost['state'] == '' && $espost['altstate'] == '') { //must pick a state for US deliveries $error .= '<li>' . __('<strong><abbr title="United States">US</abbr> State</strong> - missing or incorrect.', 'eshop') . '</li>'; } if (isset($espost['zip'])) { $valid = checkAlphaNum($espost['zip']); if ($valid == FALSE && eshop_checkreqd($reqdarray, 'zip')) { $error .= '<li>' . __('<strong>Zip/Post code</strong> - missing or incorrect.', 'eshop') . '</li>'; } } if (isset($espost['reference'])) { if ($espost['reference'] == '' && eshop_checkreqd($reqdarray, 'ref')) { $error .= '<li>' . __('<strong>Reference</strong> - missing.', 'eshop') . '</li>'; } } if (isset($espost['comments'])) { if ($espost['comments'] == '' && eshop_checkreqd($reqdarray, 'comments')) { $error .= '<li>' . __('<strong>Comments</strong> - missing.', 'eshop') . '</li>'; } } if (isset($eshopoptions['users']) && $eshopoptions['users'] == 'yes' && !is_user_logged_in()) { if (!isset($espost['eshop_users']) && eshop_checkreqd($reqdarray, 'signup')) { $error .= '<li>' . __('<strong>Sign Up</strong> - not checked.', 'eshop') . '</li>'; } } //add in error checking for any new values here $temperror = apply_filters('eshoperrorcheckout', $espost); if (!is_array($temperror)) { $error .= $temperror; } //////////////////////////////////////////////// if ('yes' == $eshopoptions['tandc_use']) { if (!isset($espost['eshop_tandc'])) { $error .= '<li><strong>' . $eshopoptions['tandc'] . '</strong>' . __(' - not checked.', 'eshop') . '</li>'; } } if (!isset($espost['eshop_payment'])) { $error .= '<li>' . __('You have not chosen a <strong>payment option</strong>.', 'eshop') . '</li>'; } if (eshop_discount_codes_check()) { $_SESSION['eshop_discount' . $blog_id] = ''; unset($_SESSION['eshop_discount' . $blog_id]); if (isset($espost['eshop_discount']) && $espost['eshop_discount'] != '') { $chkcode = valid_eshop_discount_code($espost['eshop_discount']); if (!$chkcode) { $error .= '<li>' . __('<strong>Discount Code</strong> - is not valid.', 'eshop') . '</li>'; } else { $_SESSION['eshop_discount' . $blog_id] = $espost['eshop_discount']; } } } if (isset($eshopoptions['users']) && $eshopoptions['users'] == 'yes' && isset($espost['eshop_users']) && !is_user_logged_in()) { $_SESSION['eshop_user' . $blog_id] = '1'; } if ($error != '') { $echoit .= "<p><strong class=\"eshoperror error\">" . __('There were some errors in the details you entered…', 'eshop') . "</strong></p><ul class=\"eshoperrors errors\">" . $error . '</ul>'; $first_name = $last_name = $company = $phone = $reference = ''; $email = $address1 = $address2 = $city = $country = ''; $state = $altstate = $zip = $ship_name = $ship_company = ''; $ship_phone = $ship_address = $ship_city = $ship_postcode = ''; $ship_country = $ship_state = $ship_altstate = $comments = ''; if (isset($espost['first_name'])) { $first_name = $espost['first_name']; } if (isset($espost['last_name'])) { $last_name = $espost['last_name']; } if (isset($espost['phone'])) { $phone = $espost['phone']; } if (isset($espost['reference'])) { $reference = $espost['reference']; } if (isset($espost['email'])) { $email = $espost['email']; } if (isset($espost['address1'])) { $address1 = $espost['address1']; } if (isset($espost['address2'])) { $address2 = $espost['address2']; } if (isset($espost['city'])) { $city = $espost['city']; } if (isset($espost['country'])) { $country = $espost['country']; } if (isset($espost['state'])) { $state = $espost['state']; } if (isset($espost['altstate'])) { $altstate = $espost['altstate']; } if (isset($espost['zip'])) { $zip = $espost['zip']; } if (isset($espost['ship_name'])) { $ship_name = $espost['ship_name']; } if (isset($espost['ship_company'])) { $ship_company = $espost['ship_company']; } if (isset($espost['ship_phone'])) { $ship_phone = $espost['ship_phone']; } if (isset($espost['ship_address'])) { $ship_address = $espost['ship_address']; } if (isset($espost['ship_city'])) { $ship_city = $espost['ship_city']; } if (isset($espost['ship_country'])) { $ship_country = $espost['ship_country']; } if (isset($espost['ship_state'])) { $ship_state = $espost['ship_state']; } if (isset($espost['ship_altstate'])) { $ship_altstate = $espost['ship_altstate']; } if (isset($espost['ship_postcode'])) { $ship_postcode = $espost['ship_postcode']; } if (isset($espost['comments'])) { $comments = $espost['comments']; } $chkerror = '1'; } else { if (!isset($_GET['eshopaction'])) { $shipping = 0; $echoit .= "<div class=\"hr\"></div><div class=\"eshopcheckoutconf\"><h3>" . __('<span class="noprint">Please Confirm </span>Your Details', 'eshop') . '</h3>'; // create a custom id, and shove details in database $date = date('YmdHis'); $_SESSION['date' . $blog_id] = $date; $fprice = number_format($_SESSION['final_price' . $blog_id], 2, '.', ''); $espost['amount'] = $fprice; $espost['custom'] = $date; $espost['numberofproducts'] = sizeof($_SESSION['eshopcart' . $blog_id]); //shipping if (isset($_SESSION['shipping' . $blog_id])) { $shipping = eshopShipTaxAmt(); } //discount shipping if (is_shipfree(calculate_total())) { $shipping = 0; } //shipping $espost['shipping_1'] = $shipping; $ctable = $wpdb->prefix . 'eshop_countries'; $stable = $wpdb->prefix . 'eshop_states'; if ('no' == $eshopoptions['downloads_only']) { $echoit .= '<h4>' . __('Mailing Address', 'eshop') . '</h4><ul class="eshop confirm">'; } else { $echoit .= '<h4>' . __('Contact Details', 'eshop') . '</h4><ul class="eshop confirm">'; } $echoit .= "<li><span class=\"items fullname\">" . __('Full name:', 'eshop') . "</span> " . $espost['first_name'] . " " . $espost['last_name'] . "</li>\n"; if ('no' == $eshopoptions['downloads_only']) { $echoit .= "<li class=\"company\"><span class=\"items\">" . __('Company:', 'eshop') . "</span> " . $espost['company'] . "</li>\n"; } $echoit .= "<li class=\"email\"><span class=\"items\">" . __('Email:', 'eshop') . "</span> " . $espost['email'] . "</li>\n"; if ('no' == $eshopoptions['downloads_only']) { $echoit .= "<li class=\"phone\"><span class=\"items\">" . __('Phone:', 'eshop') . "</span> " . $espost['phone'] . "</li>\n"; $echoit .= "<li class=\"address\"><span class=\"items\">" . __('Address:', 'eshop') . "</span> " . $espost['address1'] . " " . $espost['address2'] . "</li>\n"; $echoit .= "<li class=\"city\"><span class=\"items\">" . __('City or town:', 'eshop') . "</span> " . $espost['city'] . "</li>\n"; $qcode = $wpdb->escape($espost['state']); $qstate = $wpdb->get_var("SELECT stateName FROM {$stable} WHERE id='{$qcode}' limit 1"); if ($espost['altstate'] != '') { $echoit .= "<li class=\"state\"><span class=\"items\">" . __('State/County/Province:', 'eshop') . "</span> " . $espost['altstate'] . "</li>\n"; } elseif ($qstate != '') { $echoit .= "<li class=\"state\"><span class=\"items\">" . __('State/County/Province:', 'eshop') . "</span> " . $qstate . "</li>\n"; } $echoit .= "<li class=\"zip\"><span class=\"items\">" . __('Zip/Post code:', 'eshop') . "</span> " . $espost['zip'] . "</li>\n"; $qccode = $wpdb->escape($espost['country']); $qcountry = $wpdb->get_var("SELECT country FROM {$ctable} WHERE code='{$qccode}' limit 1"); $echoit .= "<li class=\"country\"><span class=\"items\">" . __('Country:', 'eshop') . "</span> " . $qcountry . "</li>\n"; } $echoit .= "</ul>\n"; // $temp = apply_filters('eshopconfcheckout', $espost); if (!is_array($temp)) { $echoit .= $temp; } // if (!isset($espost['reference'])) { $espost['reference'] = ''; } if (!isset($espost['comments'])) { $espost['comments'] = ''; } if (trim($espost['reference']) != '' && trim($espost['comments']) == '') { $echoit .= "<div class=\"eshop fld3\"><h4>" . __('Additional information', 'eshop') . "</h4>\n<ul class=\"eshop confirmref\">\n"; $echoit .= '<li><span class="items">' . __('Reference or <abbr title="Purchase Order number">PO</abbr>', 'eshop') . '</span> ' . $espost['reference'] . '</li>' . "\n"; $echoit .= '</ul></div>' . "\n"; } if (trim($espost['reference']) == '' && trim($espost['comments']) != '') { $echoit .= "<div class=\"eshop fld3\"><h4>" . __('Additional information', 'eshop') . "</h4>\n<ul class=\"eshop confirmref\">\n"; $echoit .= '<li><span class="items">' . __('Comments or instructions:', 'eshop') . '</span> ' . $espost['comments'] . '</li>' . "\n"; $echoit .= '</ul></div>' . "\n"; } if (trim($espost['reference']) != '' && trim($espost['comments']) != '') { $echoit .= "<div class=\"eshop fld3\"><h4>" . __('Additional information', 'eshop') . "</h4>\n<ul class=\"eshop confirmref\">\n"; $echoit .= '<li><span class="items">' . __('Reference or PO:', 'eshop') . '</span> ' . $espost['reference'] . '</li>' . "\n"; $echoit .= '<li><span class="items">' . __('Comments or instructions:', 'eshop') . '</span> ' . $espost['comments'] . '</li>' . "\n"; $echoit .= '</ul></div>' . "\n"; } if ('no' == $eshopoptions['downloads_only']) { if ('yes' != $eshopoptions['hide_shipping']) { if ($espost['ship_name'] != '' || $espost['ship_address'] != '' || $espost['ship_city'] != '' || $espost['ship_postcode'] != '') { $echoit .= "<div class=\"eshop fld4\"><h4>" . __('Shipping Address', 'eshop') . "</h4>\n<ul class=\"eshop confirmship\">\n"; $echoit .= "<li><span class=\"items\">" . __('Full name:', 'eshop') . "</span> " . $espost['ship_name'] . "</li>\n"; $echoit .= "<li class=\"ship_company\"><span class=\"items\">" . __('Company:', 'eshop') . "</span> " . $espost['ship_company'] . "</li>\n"; $echoit .= "<li><span class=\"items\">" . __('Phone:', 'eshop') . "</span> " . $espost['ship_phone'] . "</li>\n"; $echoit .= "<li><span class=\"items\">" . __('Address:', 'eshop') . "</span> " . $espost['ship_address'] . "</li>\n"; $echoit .= "<li><span class=\"items\">" . __('City or town:', 'eshop') . "</span> " . $espost['ship_city'] . "</li>\n"; $qcode = $wpdb->escape($espost['ship_state']); $qstate = $wpdb->get_var("SELECT stateName FROM {$stable} WHERE id='{$qcode}' limit 1"); if ($espost['ship_altstate'] != '') { $echoit .= "<li class=\"ship_state\"><span class=\"items\">" . __('State/County/Province:', 'eshop') . "</span> " . $espost['ship_altstate'] . "</li>\n"; } elseif ($qstate != '') { $echoit .= "<li class=\"ship_state\"><span class=\"items\">" . __('State/County/Province:', 'eshop') . "</span> " . $qstate . "</li>\n"; } $echoit .= "<li><span class=\"items\">" . __('Zip/Post code:', 'eshop') . "</span> " . $espost['ship_postcode'] . "</li>\n"; $qccode = $wpdb->escape($espost['ship_country']); $qcountry = $wpdb->get_var("SELECT country FROM {$ctable} WHERE code='{$qccode}' limit 1"); $echoit .= "<li class=\"shipcountry\"><span class=\"items\">" . __('Country:', 'eshop') . "</span> " . $qcountry . "</li>\n"; $echoit .= "</ul></div>\n"; } } } $echoit .= "\n"; $echoit .= "</div>\n"; } //add to a session to store address: $_SESSION['addy' . $blog_id]['first_name'] = $espost['first_name']; $_SESSION['addy' . $blog_id]['last_name'] = $espost['last_name']; $_SESSION['addy' . $blog_id]['email'] = $espost['email']; if (isset($espost['company'])) { $_SESSION['addy' . $blog_id]['company'] = $espost['company']; } else { $_SESSION['addy' . $blog_id]['company'] = ''; } if (isset($espost['phone'])) { $_SESSION['addy' . $blog_id]['phone'] = $espost['phone']; } else { $_SESSION['addy' . $blog_id]['phone'] = ''; } if (isset($espost['reference'])) { $_SESSION['addy' . $blog_id]['reference'] = $espost['reference']; } else { $_SESSION['addy' . $blog_id]['reference'] = ''; } if (isset($espost['address1'])) { $_SESSION['addy' . $blog_id]['address1'] = $espost['address1']; } else { $_SESSION['addy' . $blog_id]['address1'] = ''; } if (isset($espost['address2'])) { $_SESSION['addy' . $blog_id]['address2'] = $espost['address2']; } else { $_SESSION['addy' . $blog_id]['address2'] = ''; } if (isset($espost['city'])) { $_SESSION['addy' . $blog_id]['city'] = $espost['city']; } if (isset($espost['country'])) { $_SESSION['addy' . $blog_id]['country'] = $espost['country']; } else { $_SESSION['addy' . $blog_id]['country'] = ''; } if (isset($espost['state'])) { $_SESSION['addy' . $blog_id]['state'] = $espost['state']; } else { $_SESSION['addy' . $blog_id]['state'] = ''; } if (isset($espost['altstate']) && $espost['altstate'] != '') { $_SESSION['addy' . $blog_id]['state'] = $espost['altstate']; } if (isset($espost['zip'])) { $_SESSION['addy' . $blog_id]['zip'] = $espost['zip']; } else { $_SESSION['addy' . $blog_id]['zip'] = ''; } if (isset($espost['ship_name'])) { $_SESSION['addy' . $blog_id]['ship_name'] = $espost['ship_name']; $_SESSION['addy' . $blog_id]['ship_company'] = $espost['ship_company']; $_SESSION['addy' . $blog_id]['ship_phone'] = $espost['ship_phone']; $_SESSION['addy' . $blog_id]['ship_address'] = $espost['ship_address']; $_SESSION['addy' . $blog_id]['ship_city'] = $espost['ship_city']; $_SESSION['addy' . $blog_id]['ship_country'] = $espost['ship_country']; $_SESSION['addy' . $blog_id]['ship_state'] = $espost['ship_state']; if (isset($espost['ship_altstate']) && $espost['ship_altstate'] != '') { $_SESSION['addy' . $blog_id]['ship_state'] = $espost['ship_altstate']; } $_SESSION['addy' . $blog_id]['ship_postcode'] = $espost['ship_postcode']; } if (isset($espost['comments'])) { $_SESSION['addy' . $blog_id]['comments'] = $espost['comments']; } else { $_SESSION['addy' . $blog_id]['comments'] = ''; } if (!isset($_SESSION['shipping' . $blog_id])) { $_SESSION['shipping' . $blog_id]['cost'] = $shipping; } //grab all the POST variables and store in cookie $array = $espost; //but first make a few extra equal nothing //add others in here if needed $array['comments'] = $array['reference'] = ''; $eshopsetcookie = apply_filters('eshop_use_cookie', true); if ($eshopsetcookie == true) { $biscuits = eshop_build_cookie($array); setcookie("eshopcart", $biscuits, time() + 60 * 60 * 24 * 365); } $eshopmgincpath = apply_filters('eshop_mg_inc_path', WP_PLUGIN_DIR . '/eshop/' . $paymentmethod . '.php', $paymentmethod); include_once $eshopmgincpath; $contineproceed = '3'; } } else { //for first time form usage. if (isset($_SESSION['addy' . $blog_id])) { $first_name = $_SESSION['addy' . $blog_id]['first_name']; $last_name = $_SESSION['addy' . $blog_id]['last_name']; $company = $_SESSION['addy' . $blog_id]['company']; $phone = $_SESSION['addy' . $blog_id]['phone']; $reference = $_SESSION['addy' . $blog_id]['reference']; $email = $_SESSION['addy' . $blog_id]['email']; $address1 = $_SESSION['addy' . $blog_id]['address1']; $address2 = $_SESSION['addy' . $blog_id]['address2']; $city = ''; if (isset($_SESSION['addy' . $blog_id]['city'])) { $city = $_SESSION['addy' . $blog_id]['city']; } $country = $_SESSION['addy' . $blog_id]['country']; $state = $_SESSION['addy' . $blog_id]['state']; if (!is_numeric($state)) { $li = $wpdb->escape($state); $table = $wpdb->prefix . 'eshop_states'; $stateList = $wpdb->get_var("SELECT id FROM {$table} WHERE code='{$li}' limit 1"); $state = $stateList; } if (isset($_SESSION['addy' . $blog_id]['altstate'])) { $altstate = $_SESSION['addy' . $blog_id]['altstate']; } else { $altstate = ''; } $zip = $_SESSION['addy' . $blog_id]['zip']; /* defaults */ $ship_name = $ship_company = ''; $ship_phone = $ship_address = $ship_city = $ship_postcode = ''; $ship_country = $ship_state = $ship_altstate = $comments = ''; if (isset($_SESSION['addy' . $blog_id]['ship_name'])) { $ship_name = $_SESSION['addy' . $blog_id]['ship_name']; } if (isset($_SESSION['addy' . $blog_id]['ship_company'])) { $ship_company = $_SESSION['addy' . $blog_id]['ship_company']; } if (isset($_SESSION['addy' . $blog_id]['ship_phone'])) { $ship_phone = $_SESSION['addy' . $blog_id]['ship_phone']; } if (isset($_SESSION['addy' . $blog_id]['ship_address'])) { $ship_address = $_SESSION['addy' . $blog_id]['ship_address']; } if (isset($_SESSION['addy' . $blog_id]['ship_city'])) { $ship_city = $_SESSION['addy' . $blog_id]['ship_city']; } if (isset($_SESSION['addy' . $blog_id]['ship_country'])) { $ship_country = $_SESSION['addy' . $blog_id]['ship_country']; } if (isset($_SESSION['addy' . $blog_id]['ship_state'])) { $ship_state = $_SESSION['addy' . $blog_id]['ship_state']; if (!is_numeric($ship_state)) { $li = $wpdb->escape($ship_state); $table = $wpdb->prefix . 'eshop_states'; $stateSList = $wpdb->get_var("SELECT id FROM {$table} WHERE code='{$li}' limit 1"); $ship_state = $stateSList; } } if (isset($_SESSION['addy' . $blog_id]['ship_altstate'])) { $ship_altstate = $_SESSION['addy' . $blog_id]['ship_altstate']; } else { $ship_altstate = ''; } if (isset($_SESSION['addy' . $blog_id]['ship_postcode'])) { $ship_postcode = $_SESSION['addy' . $blog_id]['ship_postcode']; } if (isset($_SESSION['addy' . $blog_id]['comments'])) { $comments = $_SESSION['addy' . $blog_id]['comments']; } } else { $first_name = $last_name = $company = $phone = $reference = ''; $email = $address1 = $address2 = $city = $country = ''; $state = $altstate = $zip = $ship_name = $ship_company = ''; $ship_phone = $ship_address = $ship_city = $ship_postcode = ''; $ship_country = $ship_state = $ship_altstate = $comments = ''; $eshopsetcookie = apply_filters('eshop_use_cookie', true); if (isset($_COOKIE["eshopcart"]) && calculate_items() != 0 && $eshopsetcookie == true) { $crumbs = eshop_break_cookie($_COOKIE["eshopcart"]); foreach ($crumbs as $k => $v) { ${$k} = $v; } } if (is_user_logged_in() && isset($eshopoptions['users']) && 'yes' == $eshopoptions['users']) { global $current_user; get_currentuserinfo(); $crumbs = stripslashes_deep(get_the_author_meta('eshop', $current_user->ID)); if (is_array($crumbs)) { foreach ($crumbs as $k => $v) { ${$k} = esc_attr($v); } $first_name = esc_attr($current_user->user_firstname); $last_name = esc_attr($current_user->user_lastname); $email = esc_attr($current_user->user_email); } } } } if ($chkerror != 0 || !isset($espost['submit']) && $numberofproducts >= 1) { // only show form if not filled in. $echoit .= eshopShowform($first_name, $last_name, $company, $phone, $email, $address1, $address2, $city, $state, $altstate, $zip, $country, $reference, $comments, $ship_name, $ship_company, $ship_phone, $ship_address, $ship_city, $ship_postcode, $ship_state, $ship_altstate, $ship_country); } if (isset($_SESSION['eshopcart' . $blog_id])) { switch ($contineproceed) { case '1': $echoit .= '<ul class="continue-proceed eshopcp1"><li class="editcart"><a href="' . get_permalink($eshopoptions['cart']) . '">' . __('« Edit Cart or Continue Shopping', 'eshop') . '</a></li></ul>'; break; case '2': $echoit .= '<ul class="continue-proceed redirect eshopcp2"><li class="editcheckout"><a href="' . get_permalink($eshopoptions['checkout']) . '">' . __('« Edit Details or Continue Shopping', 'eshop') . '</a></li></ul>'; break; case '3': $echoit .= '<ul class="continue-proceed redirect eshopcp3"><li class="editcheckout"><a href="' . get_permalink($eshopoptions['checkout']) . '">' . __('« Edit Details or Continue Shopping', 'eshop') . '</a></li></ul>'; break; } } else { $echoit .= "<p><strong class=\"eshoperror error\">" . __('Your shopping cart is currently empty.', 'eshop') . "</strong></p>"; } return $echoit; }
function display_cart($shopcart, $change, $eshopcheckout, $pzone = '', $shiparray = '') { //The cart display. global $wpdb, $blog_id, $eshopoptions; if (!isset($_SESSION['shipping' . $blog_id]) || !is_array($_SESSION['shipping' . $blog_id])) { $_SESSION['shipping' . $blog_id] = array(); } if ($pzone == 'widget') { $pzone = ''; $iswidget = 'w'; } else { $iswidget = ''; } $echo = ''; $check = 0; $sub_total = 0; $tempshiparray = array(); //this checks for an empty cart, may not be required but leaving in just in case. $eshopcartarray = $_SESSION['eshopcart' . $blog_id]; if ($change == true) { if (isset($_SESSION['eshop_discount' . $blog_id])) { unset($_SESSION['eshop_discount' . $blog_id]); } } foreach ($eshopcartarray as $productid => $opt) { if (is_array($opt)) { foreach ($opt as $qty) { $check = $check + $qty; } } } //therefore if cart exists and has products if ($check > 0) { //global $final_price, $sub_total; // no fieldset/legend added - do we need it? if ($change == 'true') { $echo .= '<form action="' . get_permalink($eshopoptions['cart']) . '" method="post" id="eshopcartform" class="eshop eshopcart">'; } $echo .= '<table class="eshop cart" summary="' . __('Shopping cart contents overview', 'eshop') . '"> <caption>' . __('Shopping Cart', 'eshop') . '</caption> <thead> <tr class="thead">'; $echo .= '<th id="cartItem' . $iswidget . '" class="nb">' . __('Item Description', 'eshop') . '</th> <th id="cartQty' . $iswidget . '" class="bt">' . __('<abbr title="Quantity">Qty</abbr>', 'eshop') . '</th>'; $totalstring = __('Sub-Total', 'eshop'); $echo .= '<th id="cartTotal' . $iswidget . '" class="btbr">' . $totalstring . '</th>'; $etax = $eshopoptions['etax']; if ($pzone != '' && isset($eshopoptions['tax']) && $eshopoptions['tax'] == '1' || 'yes' == $eshopoptions['downloads_only'] && isset($etax['unknown']) && $etax['unknown'] != '') { $echo .= '<th id="carttax" class="bt">' . __('Tax %', 'eshop') . '</th> <th id="carttaxamt" class="btbr">' . __('Tax Amt', 'eshop') . '</th>'; } if ($iswidget == '' && $change == 'true') { $eshopdeleteheaderimage = apply_filters('eshop_delete_header_image', WP_PLUGIN_URL . '/eshop/no.png'); $echo .= '<th id="cartDelete" class="btbr"><img src="' . $eshopdeleteheaderimage . '" alt="' . __('Delete', 'eshop') . '" title="' . __('Delete', 'eshop') . '" /></th>'; } $echo .= '</tr></thead><tbody>'; //display each item as a table row $calt = 0; $shipping = 0; $totalweight = 0; $taxtotal = 0; $currsymbol = $eshopoptions['currency_symbol']; $eshopcartarray = $_SESSION['eshopcart' . $blog_id]; foreach ($eshopcartarray as $productid => $opt) { $addoprice = 0; if (is_array($opt)) { $key = $opt['option']; $calt++; $alt = $calt % 2 ? '' : ' class="alt"'; $echo .= "\n<tr" . $alt . ">"; //do the math for weight $eshop_product = maybe_unserialize(get_post_meta($opt['postid'], '_eshop_product', true)); $eimg = ''; /* image insertion */ if (is_numeric($eshopoptions['image_in_cart']) || isset($eshopoptions['widget_cart_type']) && $eshopoptions['widget_cart_type'] <= '1' && $iswidget == 'w') { $imgsize = $eshopoptions['image_in_cart']; if ($iswidget == 'w') { $imgsize = $eshopoptions['widget_cart_img']; if ($imgsize == '') { $imgsize = 100; } } $w = get_option('thumbnail_size_w'); $h = get_option('thumbnail_size_h'); if ($imgsize != '') { $w = round($w * $imgsize / 100); $h = round($h * $imgsize / 100); } if (has_post_thumbnail($opt['postid'])) { $eimg = '<a class="itemref" href="' . get_permalink($opt['postid']) . '">' . get_the_post_thumbnail($opt['postid'], array($w, $h)) . '</a>' . "\n"; } else { $eimage = eshop_files_directory(); $eshopnoimage = apply_filters('eshop_no_image', $eimage['1'] . 'noimage.png'); $eimg = '<a class="itemref" href="' . get_permalink($opt['postid']) . '"><img src="' . $eshopnoimage . '" height="' . $h . '" width="' . $w . '" alt="" /></a>' . "\n"; } } /* end */ //opsets if (isset($opt['optset'])) { $data['optset'] = $opt['optset']; $data['addoprice'] = $addoprice; $data = eshop_parse_optsets($data); $optset = '<span class="eshopoptsets">' . $data['optset'] . '</span>'; $addoprice = $data['addoprice']; } else { $optset = ''; } $echooptset = apply_filters('eshop_optset_cart_display', $optset); if (!has_filter('eshop_optset_cart_display')) { $echooptset = nl2br($optset); } $textdesc = '<a href="' . get_permalink($opt['postid']) . '">' . stripslashes($opt["pname"]) . ' <span class="eshopidetails">(' . $opt['pid'] . ' : ' . stripslashes($opt['item']) . ')</span></a>' . $echooptset; $echoimg = $eimg; if (isset($eshopoptions['widget_cart_type']) && $eshopoptions['widget_cart_type'] == '1' && $iswidget == 'w') { $textdesc = ''; } if ($iswidget == 'w' && isset($eshopoptions['widget_cart_type']) && $eshopoptions['widget_cart_type'] == '2') { $echoimg = ''; } $echo .= '<td id="prod' . $calt . $iswidget . '" headers="cartItem' . $iswidget . '" class="leftb cartitem">' . $echoimg . $textdesc . '</td>' . "\n"; $echo .= "<td class=\"cqty lb\" headers=\"cartQty{$iswidget} prod" . $calt . $iswidget . "\">"; // if we allow changes, quantities are in text boxes if ($change == true) { //generate acceptable id //$toreplace=array(" ","-","$","\r","\r\n","\n","\\","&","#",";"); $accid = $productid . $key; $accid = 'c' . md5($accid); //str_replace($toreplace, "", $accid); $echo .= '<label for="' . $accid . $iswidget . '"><input class="short" type="text" id="' . $accid . $iswidget . '" name="' . $productid . '[' . $key . ']" value="' . $opt["qty"] . '" size="3" maxlength="3" /></label>'; } else { $echo .= $opt["qty"]; } /* DISCOUNT */ $opt["price"] += $addoprice; if (is_discountable(calculate_total()) > 0) { $discount = is_discountable(calculate_total()) / 100; $disc_line = round($opt["price"] - $opt["price"] * $discount, 2); } $eline = $line_total = $opt["price"] * $opt["qty"]; if (isset($disc_line)) { $eline = $disc_line * $opt["qty"]; } $echo .= "</td>\n<td headers=\"cartTotal{$iswidget} prod" . $calt . $iswidget . "\" class=\"amts\">" . sprintf(__('%1$s%2$s', 'eshop'), $currsymbol, number_format_i18n($eline, __('2', 'eshop'))) . "</td>\n"; //TAX $etax = $eshopoptions['etax']; if ($pzone != '' && isset($eshopoptions['tax']) && $eshopoptions['tax'] == '1' || 'yes' == $eshopoptions['downloads_only'] && isset($etax['unknown']) && $etax['unknown'] != '') { if (isset($eshop_product['products'][$opt['option']]['tax']) && $eshop_product['products'][$opt['option']]['tax'] != '' && $eshop_product['products'][$opt['option']]['tax'] != '0') { if ($pzone != '') { $taxrate = eshop_get_tax_rate($eshop_product['products'][$opt['option']]['tax'], $pzone); } else { $taxrate = $etax['unknown']; } $ttotax = $line_total; if (isset($disc_line)) { $ttotax = $disc_line * $opt["qty"]; } $taxamt = round($ttotax * $taxrate / 100, 2); $echo .= '<td>' . $taxrate . '</td><td>' . sprintf(__('%1$s%2$s', 'eshop'), $currsymbol, number_format_i18n($taxamt, __('2', 'eshop'))) . '</td>'; $taxtotal += $taxamt; $_SESSION['eshopcart' . $blog_id][$productid]['tax_rate'] = $taxrate; $_SESSION['eshopcart' . $blog_id][$productid]['tax_amt'] = $taxamt; } else { $echo .= '<td></td><td></td>'; } } // if ($iswidget == '' && $change == 'true') { $eshopdeleteimage = apply_filters('eshop_delete_image', WP_PLUGIN_URL . '/eshop/no.png'); $echo .= '<td headers="cartDelete" class="deletecartitem"><label for="delete' . $productid . $iswidget . '" class="hide">' . __('Delete this item', 'eshop') . '</label><input type="image" src="' . $eshopdeleteimage . '" id="delete' . $productid . $iswidget . '" name="eshopdeleteitem[' . $productid . ']" value="' . $opt["qty"] . '" title="' . __('Delete this item', 'eshop') . '"/></td>'; } $echo .= "</tr>\n"; if (isset($disc_line)) { $sub_total += $disc_line * $opt["qty"]; } else { $sub_total += $line_total; } //weight if (isset($opt['weight'])) { $totalweight += $opt['weight'] * $opt['qty']; } } } // display subtotal row - total for products only $disc_applied = ''; if (is_discountable(calculate_total()) > 0) { $discount = is_discountable(calculate_total()); $disc_applied = '<small>(' . sprintf(__('Including Discount of <span>%s%%</span>', 'eshop'), number_format_i18n(round($discount, 2), 2)) . ')</small>'; } if ($iswidget == '' && $change == 'true') { $emptycell = '<td headers="cartDelete" class="eshopempty"></td>'; } else { $emptycell = ''; } if ($pzone != '' && isset($taxtotal) && isset($eshopoptions['tax']) && $eshopoptions['tax'] == '1' || 'yes' == $eshopoptions['downloads_only'] && isset($etax['unknown']) && $etax['unknown'] != '') { $emptycell = '<td headers="subtotal carttaxamt" class="amts lb" colspan="2">' . sprintf(__('%1$s%2$s', 'eshop'), $currsymbol, number_format_i18n($taxtotal, __('2', 'eshop'))) . '</td>'; } $echo .= "<tr class=\"stotal\"><th id=\"subtotal{$iswidget}\" class=\"leftb\">" . __('Sub-Total', 'eshop') . ' ' . $disc_applied . "</th><td headers=\"subtotal{$iswidget} cartTotal{$iswidget}\" class=\"amts lb\" colspan=\"2\">" . sprintf(__('%1$s%2$s', 'eshop'), $currsymbol, number_format_i18n($sub_total, __('2', 'eshop'))) . "</td>{$emptycell}</tr>\n"; $final_price = $sub_total; $_SESSION['final_price' . $blog_id] = $final_price; // SHIPPING PRICE HERE $shipping = 0; //$pzone will only be set after the checkout address fields have been filled in // we can only work out shipping after that point if ($pzone != '' || 'yes' == $eshopoptions['downloads_only'] && isset($etax['unknown']) && $etax['unknown'] != '') { if ($pzone != '') { //shipping for cart. if ($eshopoptions['shipping_zone'] == 'country') { $table = $wpdb->prefix . 'eshop_countries'; } else { $table = $wpdb->prefix . 'eshop_states'; } $table2 = $wpdb->prefix . 'eshop_rates'; switch ($eshopoptions['shipping']) { case '1': //( per quantity of 1, prices reduced for additional items ) foreach ($shiparray as $nowt => $shipclass) { //add to temp array for shipping if (!in_array($shipclass, $tempshiparray)) { if ($shipclass != 'F') { array_push($tempshiparray, $shipclass); $shipzone = 'zone' . $pzone; $shipcost = $wpdb->get_var("SELECT {$shipzone} FROM {$table2} WHERE class='{$shipclass}' and items='1' and rate_type='shipping' limit 1"); $shipping += $shipcost; } } else { if ($shipclass != 'F') { $shipzone = 'zone' . $pzone; $shipcost = $wpdb->get_var("SELECT {$shipzone} FROM {$table2} WHERE class='{$shipclass}' and items='2' and rate_type='shipping' limit 1"); $shipping += $shipcost; } } } break; case '2': //( once per shipping class no matter what quantity is ordered ) foreach ($shiparray as $nowt => $shipclass) { if (!in_array($shipclass, $tempshiparray)) { array_push($tempshiparray, $shipclass); if ($shipclass != 'F') { $shipzone = 'zone' . $pzone; $shipcost = $wpdb->get_var("SELECT {$shipzone} FROM {$table2} WHERE class='{$shipclass}' and items='1' and rate_type='shipping' limit 1"); $shipping += $shipcost; } } } break; case '3': //( one overall charge no matter how many are ordered ) $shiparray = array_unique($shiparray); foreach ($shiparray as $nowt => $shipclass) { if ($shipclass != 'F') { $shipzone = 'zone' . $pzone; $shipcost = $wpdb->get_var("SELECT {$shipzone} FROM {$table2} WHERE class='A' and items='1' and rate_type='shipping' limit 1"); $shipping += $shipcost; } } break; case '4': //by weight/zone etc //$totalweight $shipzone = 'zone' . $pzone; $shipcost = $wpdb->get_var("SELECT {$shipzone} FROM {$table2} where weight <= '{$totalweight}' && class='{$shiparray}' and rate_type='ship_weight' order by weight DESC limit 1"); $shipping += $shipcost; $_SESSION['eshopshiptype' . $blog_id] = $shiparray; } //display shipping cost //discount shipping? if (is_shipfree(calculate_total()) || eshop_only_downloads()) { $shipping = 0; } $echo .= '<tr class="alt shippingrow"><th headers="cartItem' . $iswidget . '" id="scharge" class="leftb">'; if ($eshopoptions['shipping'] == '4' && !eshop_only_downloads() && $shiparray != '0') { $eshopoptions['ship_types'] = trim($eshopoptions['ship_types']); $typearr = explode("\n", $eshopoptions['ship_types']); //darn, had to add in unique to be able to go back a page $echo .= ' <a href="' . get_permalink($eshopoptions['checkout']) . '?eshoprand=' . rand(2, 100) . '#shiplegend" title="' . __('Change Shipping', 'eshop') . '">' . stripslashes(esc_attr($typearr[$shiparray - 1])) . '</a> '; } else { $echo .= __('Shipping', 'eshop'); } if ($eshopoptions['cart_shipping'] != '') { $ptitle = get_post($eshopoptions['cart_shipping']); $echo .= ' <small>(<a href="' . get_permalink($eshopoptions['cart_shipping']) . '">' . __($ptitle->post_title, 'eshop') . '</a>)</small>'; } $echo .= '</th> <td headers="cartItem scharge" class="amts lb" colspan="2">' . sprintf(__('%1$s%2$s', 'eshop'), $currsymbol, number_format_i18n($shipping, __('2', 'eshop'))) . '</td>'; if ($pzone != '' && isset($taxtotal) && isset($eshopoptions['tax']) && $eshopoptions['tax'] == '1') { $taxrate = eshop_get_tax_rate($eshopoptions['etax']['shipping'], $pzone); $ttotax = $shipping; $taxamt = round($ttotax * $taxrate / 100, 2); $taxtext = ''; if ($taxamt > '0.00') { $taxtext = sprintf(__('%1$s%2$s', 'eshop'), $currsymbol, number_format_i18n($taxamt, __('2', 'eshop'))); } $echo .= '<td>' . $taxrate . '</td><td>' . $taxtext . '</td>'; $shiptax = $taxamt; $_SESSION['shipping' . $blog_id]['tax'] = $shiptax; $_SESSION['shipping' . $blog_id]['taxrate'] = $taxrate; } $echo .= '</tr>'; $_SESSION['shipping' . $blog_id]['cost'] = $shipping; $final_price = $sub_total + $shipping; $_SESSION['final_price' . $blog_id] = $final_price; } $excltax = ''; if (isset($taxtotal) && isset($eshopoptions['tax']) && $eshopoptions['tax'] == '1') { $excltax = __('(excl.tax)', 'eshop'); } $echo .= '<tr class="total"><th id="cTotal' . $iswidget . '" class="leftb">' . __('Total Order Charges', 'eshop') . "</th>\n<td headers=\"cTotal{$iswidget} cartTotal{$iswidget}\" colspan=\"2\" class = \"amts lb\"><strong>" . sprintf(__('%1$s%2$s <span>%3$s</span>', 'eshop'), $currsymbol, number_format_i18n($final_price, __('2', 'eshop')), $excltax) . "</strong></td>"; if (isset($shiptax) && isset($eshopoptions['tax']) && $eshopoptions['tax'] == '1') { $withtax = $final_price + $shiptax + $taxtotal; } if ('yes' == $eshopoptions['downloads_only'] && isset($etax['unknown']) && $etax['unknown'] != '') { $withtax = $final_price + $taxtotal; } if (isset($eshopoptions['tax']) && $eshopoptions['tax'] == '1') { $echo .= '<td headers="taxtotal" class="taxttotal amts lb" colspan="2"><strong>' . sprintf(__('%1$s%2$s <span>%3$s</span>', 'eshop'), $currsymbol, number_format_i18n($withtax, __('2', 'eshop')), __('(incl.tax)', 'eshop')) . '</strong></td>'; } $echo .= "</tr>"; } $echo .= "</tbody></table>\n"; // display unset/update buttons if ($change == true) { $echo .= "<div class=\"cartopt\"><input type=\"hidden\" name=\"save\" value=\"true\" />\n<input type=\"hidden\" name=\"eshopnon\" value=\"set\" />\n"; $echo .= wp_nonce_field('eshop_add_product_cart', '_wpnonce', true, false); $echo .= "<p><label for=\"update\"><input type=\"submit\" class=\"button\" id=\"update\" name=\"update\" value=\"" . __('Update Cart', 'eshop') . "\" /></label>"; $echo .= "<label for=\"unset\"><input type=\"submit\" class=\"button\" id=\"unset\" name=\"unset\" value=\"" . __('Empty Cart', 'eshop') . "\" /></label></p>\n"; $echo .= "</div>\n"; } if ($change == 'true') { $echo .= "</form>\n"; } } else { //if cart is empty - display a message - this is only a double check and should never be hit $echo .= "<p class=\"eshoperror error\">" . __('Your shopping cart is currently empty.', 'eshop') . "</p>\n"; } if ($eshopoptions['status'] != 'live') { $echo = "<p class=\"testing\"><strong>" . __('Test Mode — No money will be collected.', 'eshop') . "</strong></p>\n" . $echo; } if (isset($_SESSION['eshop_discount' . $blog_id]) && valid_eshop_discount_code($_SESSION['eshop_discount' . $blog_id])) { $echo .= '<p class="eshop_dcode">' . sprintf(__('Discount Code <span>%s</span> has been applied to your cart.', 'eshop'), $_SESSION['eshop_discount' . $blog_id]) . '</p>' . "\n"; } //test if (isset($totalweight)) { $_SESSION['eshop_totalweight' . $blog_id]['totalweight'] = $totalweight; } if ($iswidget == 'w') { $echo .= '<br /><a class="cartlink" href="' . get_permalink($eshopoptions['cart']) . '">' . __('Edit Cart', 'eshop') . '</a>'; $echo .= '<br /><a class="checkoutlink" href="' . get_permalink($eshopoptions['checkout']) . '">' . __('Checkout', 'eshop') . '</a>'; } return $echo; }
<?php print $tax; ?> % is $ <?php print number_format($total, 2); ?> </p> <?php } if (isset($_POST['submitted'])) { if (is_numeric($_POST['quantity']) && is_numeric($_POST['price'])) { if (is_numeric($_POST['tax'])) { calculate_total($_POST['quantity'], $_POST['price'], $_POST['tax']); } else { calculate_total($_POST['quantity'], $_POST['price']); } } else { echo '<h1>Error!</h1>'; echo '<p class="error">Please enter a valid quantity and price.</p>'; } } ?> <h1>Widget cost calculator</h1> <form action="calculator.php" method="post"> <p>Quantity: <input type="text" name="quantity" size="5" maxlength="5" value="<?php if (isset($_POST['quantity'])) { echo $_POST['quantity']; }
// Turn 5% into .05. $total = $_POST['quantity'] * $_POST['price'] * ($taxrate + 1); $total = number_format($total, 2); } // End of function. // Check if the form has been submitted. if (isset($_POST['submitted'])) { if (is_numeric($_POST['quantity']) && is_numeric($_POST['price'])) { // Print the heading. echo '<h1 id="mainhead">总计:</h1>'; $total = NULL; // Initialize $total. if (is_numeric($_POST['tax'])) { calculate_total($_POST['tax']); } else { calculate_total(); } echo '<p>总计购买: ' . $_POST['quantity'] . ' 件商品,每件 ' . number_format($_POST['price'], 2) . ' 元,总价(含税)为 ' . $total . ' 元.</p>'; // Print some spacing. echo '<p><br /></p>'; } else { // Invalid submitted values. echo '<h1 id="mainhead">错误!</h1> <p class="error">请输入有效的商品数量及单价!</p><p><br /></p>'; } } // End of main isset() IF. // Leave the PHP section and create the HTML form. ?> <h2>花费计算</h2> <form action="calculator.php" method="post">