PHP - Help Pls !! Customize Shipping Cost
Hi there, I would like to customize $shippingCost in my shopping cart. I follow a tutorial from:
http://www.phpwebcommerce.com/plaincart/index.php This tutorial using flat shipping rate, how to customize shippingCost based on the product weight ? Example: shipping method will based on weight & place within Malaysia: west malaysia, up to 1kg = rm9 east malaysia, up to 1kg = rm12 west malaysia, up to 2kg = rm12 east malaysia, up to 2kg = rm16 west malaysia, up to 5kg = rm18 east malaysia, up to 5kg = rm32 west malaysia, up to 10kg = rm24 east malaysia, up to 10kg = rm48 Do i need to create a new field inside my database for product weight ? is it $weight * $product_quantity ? Does anyone know how to accomplish this customization? . Please help because I am very confuse. Thank you in advanced checkout-functions.php: Code: [Select] <?php require_once 'config.php'; /********************************************************* * CHECKOUT FUNCTIONS *********************************************************/ function saveOrder() { $orderId = 0; $shippingCost = 5; $requiredField = array('hidShippingFirstName', 'hidShippingLastName', 'hidShippingAddress1', 'hidShippingCity', 'hidShippingPostalCode', 'hidPaymentFirstName', 'hidPaymentLastName', 'hidPaymentAddress1', 'hidPaymentCity', 'hidPaymentPostalCode'); if (checkRequiredPost($requiredField)) { extract($_POST); // make sure the first character in the // customer and city name are properly upper cased $hidShippingFirstName = ucwords($hidShippingFirstName); $hidShippingLastName = ucwords($hidShippingLastName); $hidPaymentFirstName = ucwords($hidPaymentFirstName); $hidPaymentLastName = ucwords($hidPaymentLastName); $hidShippingCity = ucwords($hidShippingCity); $hidPaymentCity = ucwords($hidPaymentCity); $cartContent = getCartContent(); $numItem = count($cartContent); // save order & get order id $sql = "INSERT INTO tbl_order(od_date, od_last_update, od_shipping_first_name, od_shipping_last_name, od_shipping_address1, od_shipping_address2, od_shipping_phone, od_shipping_state, od_shipping_city, od_shipping_postal_code, od_shipping_cost, od_payment_first_name, od_payment_last_name, od_payment_address1, od_payment_address2, od_payment_phone, od_payment_state, od_payment_city, od_payment_postal_code) VALUES (NOW(), NOW(), '$hidShippingFirstName', '$hidShippingLastName', '$hidShippingAddress1', '$hidShippingAddress2', '$hidShippingPhone', '$hidShippingState', '$hidShippingCity', '$hidShippingPostalCode', '$shippingCost', '$hidPaymentFirstName', '$hidPaymentLastName', '$hidPaymentAddress1', '$hidPaymentAddress2', '$hidPaymentPhone', '$hidPaymentState', '$hidPaymentCity', '$hidPaymentPostalCode')"; $result = dbQuery($sql); // get the order id $orderId = dbInsertId(); if ($orderId) { // save order items for ($i = 0; $i < $numItem; $i++) { $sql = "INSERT INTO tbl_order_item(od_id, pd_id, od_qty) VALUES ($orderId, {$cartContent[$i]['pd_id']}, {$cartContent[$i]['ct_qty']})"; $result = dbQuery($sql); } // update product stock for ($i = 0; $i < $numItem; $i++) { $sql = "UPDATE tbl_product SET pd_qty = pd_qty - {$cartContent[$i]['ct_qty']} WHERE pd_id = {$cartContent[$i]['pd_id']}"; $result = dbQuery($sql); } // then remove the ordered items from cart for ($i = 0; $i < $numItem; $i++) { $sql = "DELETE FROM tbl_cart WHERE ct_id = {$cartContent[$i]['ct_id']}"; $result = dbQuery($sql); } } } return $orderId; } /* Get order total amount ( total purchase + shipping cost ) */ function getOrderAmount($orderId) { $orderAmount = 0; $sql = "SELECT SUM(pd_price * od_qty) FROM tbl_order_item oi, tbl_product p WHERE oi.pd_id = p.pd_id and oi.od_id = $orderId UNION SELECT od_shipping_cost FROM tbl_order WHERE od_id = $orderId"; $result = dbQuery($sql); if (dbNumRows($result) == 2) { $row = dbFetchRow($result); $totalPurchase = $row[0]; $row = dbFetchRow($result); $shippingCost = $row[0]; $orderAmount = $totalPurchase + $shippingCost; } return $orderAmount; } ?> any help will be greatly appreciated Similar TutorialsHi there Does anyone know where can i get php/mysql calculation weight & shipping cost tutorial ? Thank you in advanced! Hi All, Just now I had a thought in mind for using regular expression in implode. I know I can get the solution using foreach loop but just trying whether can we do it without using foreach. I have an array here I want to create a table with array. I can do it using for or foreach loop but just a thought came in my mind doing it without using loop. $arr = array(1,2,3,4,5); echo "<table border='2'>"; echo "<tr>".implode("<td>[u]I WANT MY VALUES HERE[/u]</td>",$arr)."</tr>"; echo "</table>"; can we pass regular expression in implode() so that i will get record something like this <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=348108.0 Hi,
Please can someone point me in the right direction to solving this.
The following code set the postage rate on a basket. It selects the lowest postage assigned to a product and set that as the postage rate.
I now need this to work the opposite way round and select the highest postage rate of the added products.
The postage rates are stored in the database as:
0=0.00
1=4.95
2=7.95
3=12.95
So it looks like somewhere there has been something added that tells it to always give preference to the "0" of any products giving the lowest postage but I'm sure on this....
Thanks.
//set default postage value outside loop $postagerate = 15.00; I would like to customize my product-list page to display all my products in a grid with an ADD TO CART option for each product. That means i have two ADD TO CART button on the site, in productDetail.php there is a ADD TO CART button original from the tutorial, i need customize another ADD TO CART button on productList.php. Does anyone know how to accomplish this customization? . Please help because I am stuck with the coding for 3weeks Tutorial site: http://www.phpwebcommerce.com/plaincart/index.php productDetail.php: Code: [Select] <?php if (!defined('WEB_ROOT')) { exit; } $product = getProductDetail($pdId, $catId); // we have $pd_name, $pd_price, $pd_description, $pd_image, $cart_url extract($product); ?> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td align="center"><img src="<?php echo $pd_image; ?>" border="0" alt="<?php echo $pd_name; ?>" width="230" height="170"></td> <td valign="middle"> <strong><?php echo $pd_name; ?></strong><br> Price : <?php echo displayAmount($pd_price); ?><br> <?php // if we still have this product in stock // show the 'Add to cart' button if ($pd_qty > 0) { ?> <input type="button" name="btnAddToCart" value="Add To Cart >" onClick="window.location.href='<?php echo $cart_url; ?>';" class="addToCartButton"> <?php } else { echo 'Out Of Stock'; } ?> </td> </tr> <tr align="left"> <td colspan="2"><?php echo $pd_description; ?></td> </tr> </table> productList.php: Code: [Select] <?php if (!defined('WEB_ROOT')) { exit; } $productsPerRow = 2; $productsPerPage = 8; //$productList = getProductList($catId); $children = array_merge(array($catId), getChildCategories(NULL, $catId)); $children = ' (' . implode(', ', $children) . ')'; $sql = "SELECT pd_id, pd_name, pd_price, pd_thumbnail, pd_qty, c.cat_id FROM tbl_product pd, tbl_category c WHERE pd.cat_id = c.cat_id AND pd.cat_id IN $children ORDER BY pd_name"; $result = dbQuery(getPagingQuery($sql, $productsPerPage)); $pagingLink = getPagingLink($sql, $productsPerPage, "c=$catId"); $numProduct = dbNumRows($result); // the product images are arranged in a table. to make sure // each image gets equal space set the cell width here $columnWidth = (int)(100 / $productsPerRow); ?> <table width="100%" border="0" cellspacing="0" cellpadding="20"> <?php if ($numProduct > 0 ) { $i = 0; while ($row = dbFetchAssoc($result)) { extract($row); if ($pd_thumbnail) { $pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail; } else { $pd_thumbnail = WEB_ROOT . 'images/no-image-small.png'; } if ($i % $productsPerRow == 0) { echo '<tr>'; } // format how we display the price $pd_price = displayAmount($pd_price); echo "<td width=\"$columnWidth%\" align=\"center\"><a href=\"" . $_SERVER['PHP_SELF'] . "?c=$catId&p=$pd_id" . "\"><img src=\"$pd_thumbnail\" border=\"0\" width=\"230\" height=\"170\"><br>$pd_name</a><br>Price : $pd_price<br>"; // format display add to cart echo "<input type=\"button\" name=\"btnAddToCart\" value=\"Add To Cart >\" onClick=\"window.location.href='<?php echo $cart_url;?>';\" >"; // if the product is no longer in stock, tell the customer if ($pd_qty <= 0) { echo "<br>Out Of Stock"; } echo "</td>\r\n"; if ($i % $productsPerRow == $productsPerRow - 1) { echo '</tr>'; } $i += 1; } if ($i % $productsPerRow > 0) { echo '<td colspan="' . ($productsPerRow - ($i % $productsPerRow)) . '"> </td>'; } } else { ?> <tr><td width="100%" align="center" valign="center">No products in this category</td></tr> <?php } ?> </table> <p align="center"><?php echo $pagingLink; ?></p> Product-functions.php: Code: [Select] <?php require_once 'config.php'; /********************************************************* * PRODUCT FUNCTIONS **********************************************************/ /* Get detail information of a product */ function getProductDetail($pdId, $catId) { $_SESSION['shoppingReturnUrl'] = $_SERVER['REQUEST_URI']; // get the product information from database $sql = "SELECT pd_name, pd_description, pd_price, pd_image, pd_qty FROM tbl_product WHERE pd_id = $pdId"; $result = dbQuery($sql); $row = dbFetchAssoc($result); extract($row); $row['pd_description'] = nl2br($row['pd_description']); if ($row['pd_image']) { $row['pd_image'] = WEB_ROOT . 'images/product/' . $row['pd_image']; } else { $row['pd_image'] = WEB_ROOT . 'images/no-image-large.png'; } $row['cart_url'] = "cart.php?action=add&p=$pdId"; return $row; } ?> any help will be greatly appreciated Hey everyone, Just want to say please move this thread if this is the wrong place. I have made a shopping cart for a client from scratch, and now the ONLY thing stopping me from finishing it is a SHIPPING calculator. ALL the stupid API's from these companies like UPS make absolutely no sense, half of them required PHP extensions to be installed, and I got many errors with that departement too... Now how does osCommerce or Ebay do this? Is there anywhere out there where there is a tutorial on completing this task? I have a list of id's between 1 - 8 which represents a print size that I need to use to calculate shipping costs, but the calculation that I need to perform is complicated. I will try to explain to the best of my abilities. I also need to query a database table to make sure the shipping rates are always up-to-date id's <= 4 will ship for $4.95 now matter how many id's are listed. Eg: 1,2,3,4,3,2,4,2,4 will ship for a total of $4.95 will query price db as 1 id's <= 5 will ship for $6.00 now mater how many id's are listed. Eg: 1,3,3,1,2,3,5,5,5,4,3,3 will ship for a total of $6 will query price db as 2 id's <= 6 will ship for $8.00 now mater how many id's are listed. Eg: 1,3,6,1,6,3,5,5,5,4,3,3 will ship for a total of $8.00 will query price db as 3 id 7 will ship for $5 * Quanity + any of the examples above will query price db as 4 id 8 will ship for $15 * Quantity + any of the examples above will query price db as 5 table structure for shiprates is id, price This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=345769.0 the PHP below counts the number of items but not the total quantity (quantity_1) to calculate the value of $shipping. any ideas? link to form: http://crsecrets.com/test01/order.html FORM Code: [Select] <TD>Herbal Hair Rejuvenator, Unscented <FONT SIZE="-2">(4oz. jar)</FONT><input type="hidden" name="item_name_1" value="Herbal Hair Rejuvenator, Unscented (4oz. jar)" /> </TD> <TD align="center" id="table"><input name="quantity_1" type="text" value="" size="6" maxlength="2" /></TD> <TD align="center">$13.50<input type="hidden" name="amount_1" value="13.50" /></TD> Code: [Select] [m]<?php $products = array(); $url = "?business=*********$handling_cart=7.00"; foreach ($_POST as $k=>$v) { preg_match("/\_(\d{1,3})$/",$k,$match); $key = $match[1]; $products[$key][$k] = $v; } $i=1; foreach ($products as $k=>$v) { if ($v['quantity_'.$k] > 0) { foreach ($v as $k1=>$v1) { $key = explode("_",$k1); switch($key[0]) { case 'item': $var = "item_name_" . $i; break; case 'quantity': $var = "quantity_" . $i; break; case 'amount': $var = "amount_" . $i; break; } //get shipping for additional items above 3 if ($i <= 2) { $shipping = "0.00"; } else { $shipping = "1.00"; } $shipping = ($shipping * $v['quantity_' . $k]); $url .= "&" . $var . "=" . urlencode($v1); } $url .= "&shipping_" . $i . "=" . $shipping; $i++; } } #echo $url; header("Location: https://www.paypal.com/cgi-bin/webscr" . $url); exit; ?>[/m] Hi there, I am trying to edit my shopping cart page so that i can use a different shipping rate for each country that i ship to. At the minute this is the code i use: */ if(isset($_GET['eushipping'])||(isset($_POST['rec_country'])&&$_POST['rec_country']!='uk')){ $shipping = ceil($total/30.00)*20.00; } I though it if i just changed the value 'eushipping' to the country option value it would work but it doesn't. Can anyone point me in the write direction of what i need to change? Many thanks. Hash Hey guys,
I need some help with a simple script a friend wrote for me but isn't returning the correct values. I'm looking to get this script working but my PHP skills are abysmal and I can't for the life of me figure out whats the best way to do this. I've tried contacting my friend but he's moving cross-country so I'm hoping you guys can give me some advice.
The script is supposed to return a total shipping price based on the weight of products that are passed to it via an API and the location of the visitor. There are a total of 3 different products (Product A, Product B, Product C) each with it's own weight in grams and it's own shipping rate. The script is needs to follow the following rules:
When 1 product (either Product A, B, or C) is in the cart it returns the full fixed shipping price for either US or International Shipping based on $isInternational
When 2 or more of Product A or B are added to the cart the full shipping is taken for the heaviest item and a fixed price is added for each additional item (Product and B each have their own fixed prices)
When Product C is added to the cart it returns a fixed based on US or International (Product C ships separately and doesn't depend on the weight/prices of Product A or B)
The product weights/prices a
Product A: Hi there, I am working on an e-commerce website on PHP and MySql. The website has products that suppliers can add and edit, which works fine. Now we are required to create and add a shipping profile to the products. That is, a supplier can set up a profile where he'll specify, for example: Setting Shipping charges of Product weight $10/kg for US shipping $20/Kg for Europe $25/Kg for Rest of the world. Once this profile is setup, I would need to attach this profile to a product. Well, I can create a table named ProductProfile and enter this weight info and how do I go about attaching this to a product. Any comment/feedback are always welcome! Thank you Posted this in the help section but I realized I would have better luck posting this in this forum.
I need some urgent help with a simple script a friend wrote for me but isn't returning the correct values. I'm looking to get this script working but my PHP skills are abysmal and I can't for the life of me figure out whats the best way to do this. I've tried contacting my friend but he's moving cross-country so I'm hoping someone could help me quickly. I require the script to be working for a small project of mine so I need some help within the next 3-4 hrs if possible.
The script is supposed to return a total shipping price based on the weight of products that are passed to it via an API and the location of the visitor. There are a total of 3 different products (Product A, Product B, Product C) each with it's own weight in grams and it's own shipping rate. The script is needs to follow the following rules:
When 1 product (either Product A, B, or C) is in the cart it returns the full fixed shipping price for either US or International Shipping based on $isInternational
When 2 or more of Product A or B are added to the cart the full shipping is taken for the heaviest item and a fixed price is added for each additional item (Product and B each have their own fixed prices)
When Product C is added to the cart it returns a fixed based on US or International (Product C ships separately and doesn't depend on the weight/prices of Product A or B)
The product weights/prices a
Product A: I am using extra fees extension, if customer chooses shipping method: Pick from the store how to remove Handling fees(extra fees extension).
How to solve by using observer? Edited August 12, 2019 by aveevaI have couple of shipping methods DHL & FedEx, if selected products exits in cart show only selected shipping method, how to archive using shopping cart pricing rule or any other way to do this?
I have been looking at this code most of the morning and do not have a clue what is wrong with the code. I am hoping its not a stupid mistake, can someone please help me out? thank you
<title>Inputing Travel Detials</title> <header> <h1 align="center"> Adding Travel Detials </h1> <body> <p> <center><img src="cyberwarfareimage1.png" alt="Squadron logo" style="width:200px;height:200px" style="middle"></center> <table border="1"> <tr> <td><a href="index.php"> Home Page </a></td> <td><a href="administratorhomepage.html">Administrator Home Page </a></td> <td><a href="viewhomepage.html">View Home Page </a></td> <td><a href="Inputhomepage.html">Input Home Page </a></td> <td><a href="traveldetials.html">Enter More Travel Detials </a></td> </table> </p> <?php include "connection.php"; $Applicant_ID = $_POST["Applicant_ID"]; $Method_Of_Travel = $_POST["Method_Of_Travel"]; $Cost = $_POST["Cost"]; $ETA = $_POST["ETA"]; $Main_Gate_Advised = $_POST["Main_Gate_Advised"]; $query = ("UPDATE `int_board_applicant` SET `Method_Of_Travel`=`$Method_Of_Travel', `Cost`=`$Cost', `ETA`='$ETA', `Main_Gate_Advised`='$Main_Gate_Advised' WHERE `Applicant_ID`='$Applicant_ID'"); $result = mysqli_query($dbhandle, $query) or die(mysqli_error($dbhandle)); if($result){ echo "Success!"; } else{ echo "Error."; } // successfully insert data into database, displays message "Successful". if($query){ echo "Successful"; } else { echo "Data not Submitted"; } //closing the connection mysqli_close($dbhandle) ?> For example if I wanted to let any user to be able to add a page to my site where they can title it and give a description of it or whatever they like to it, what would the code be for doing this type of thing? I use the Wholesale Suite Premium Prices plugin with WooCommerce. I have 6 specific wholesale roles out of 15 that I wish to hide two specific shipping methods from being selected for the 6 exceptions. I'm just trying this on my staging server at this time using a code snippet example that I found and modified for my specific conditions. Would the following work for this purpose? /* Hide specific shipping methods for specific wholesale roles */ add_filter( 'woocommerce_package_rates', function( $shipping_rates ) { // User role and shipping method ID to hide for the user role $role_shipping_method_arr = array( 'ws_silvia_silver' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_silver_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_silver_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), ); // Getting the current user role $curr_user = wp_get_current_user(); $curr_user_data = get_userdata($current_user->ID); // Wholesale Suite Roles if (isset($current_user) && class_exists('WWP_Wholesale_Roles')) { $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance(); $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole(); // Loop through the user role and shipping method pair foreach( $role_shipping_method_arr as $role => $shipping_methods_to_hide ) { // Check if defined role exist in current user role or not if( in_array( $role, $current_user->roles) ) { // Loop through all the shipping rates foreach( $shipping_rates as $shipping_method_key => $shipping_method ) { $shipping_id = $shipping_method->get_id(); // Unset the shipping method if found if( in_array( $shipping_id, $shipping_methods_to_hide) ) { unset($shipping_rates[$shipping_method_key]); } } } } } return $shipping_rates; }); Any insights as to how to accomplish this would be greatly appreciated. Lyse |