roldahayes Posted January 31, 2014 Share Posted January 31, 2014 Hi, I am trying to work out how to adjust my shopping cart to remove the delivery charge from orders where the customer selects to collect from store... This code displays the total amount including the $Postage which is retrieved earlier on. $shoprow = mysql_fetch_assoc($result); $Basket_total = number_format(htmlspecialchars($shoprow['Basket_total']), 2); Could anyone point me in the right direction to code it to remove this variable? Quote Link to comment https://forums.phpfreaks.com/topic/285830-how-to-remove-postage-from-this/ Share on other sites More sharing options...
davidannis Posted January 31, 2014 Share Posted January 31, 2014 (edited) You have not posted enough code to answer the question. We ave no idea what variable the postage is stored in or what you want to do with the new total after you subtract postage. A guess would be: $Basket_total = number_format(htmlspecialchars($shoprow['Basket_total']-$myPostageVariable), 2); Be careful, the total stored in the database won't change just because it changed in the program. YOu need to write it back to your db if you want it changed there too. Edited January 31, 2014 by davidannis Quote Link to comment https://forums.phpfreaks.com/topic/285830-how-to-remove-postage-from-this/#findComment-1467219 Share on other sites More sharing options...
roldahayes Posted January 31, 2014 Author Share Posted January 31, 2014 Thanks, I just need it to display what the total basket cost is minus the postage rate. Basically need it to "undo" what it has done earlier... Would unset() be appropriate here? Quote Link to comment https://forums.phpfreaks.com/topic/285830-how-to-remove-postage-from-this/#findComment-1467221 Share on other sites More sharing options...
.josh Posted January 31, 2014 Share Posted January 31, 2014 So you are saying that $Basket_total has the total price, including shipping. IOW [product price] + [shipping price]. So you want to subtract [shipping price] from $Basket_total. So in order to do what you want to do, you need to know what [shipping price] is, so that you can subtract it from $Basket_total Example: // this is in principle what your existing code would have had to do to get your $Basket_total $Product_price = 10; $Shipping = 2; $Basket_total = $product_price + $shipping; // So later on in your code, you're wanting to be able to output this: echo $Product_price; // but the variable you currently have to work with is this: echo $Basket_total; // so you need to be able to do this: echo $Basket_total - $Shipping; If all you have to work with at this point is the value of $Basket_total, then you can't do what you're wanting to do. The original shipping price must somehow be exposed in order for you to do that, so that you can subtract it. unset won't do anything for you except delete the entire variable. You don't want to do that; you want to subtract a value from the variable, which is basic math operation. So that is essentially what Davidannis was saying when he said you didn't post enough code. We cannot tell you whether or not the postage price by itself is available, since we can't see your code as a whole. So.. do you have that value set in a variable in your script somewhere? Or perhaps it's stored in your database to query for as well? Without it, you will not be able to separate the two, any more than you'd be able to separate the following: // i have this... $total = 10 + 2; // how do I get just that 10 from $total? // you can't, unless you do this instead: $x = 10; $y = 2; $total = $x + $y; // then you can do this: echo $x; // or this: echo $total - $y; And as a sidenote, I echo Davidannis's last statement: displaying the price without the shipping is not the same thing as only charging the visitor the price. In order to only charge the visitor for actual price without shipping, you will need to update whatever code that actually charges the visitor. Quote Link to comment https://forums.phpfreaks.com/topic/285830-how-to-remove-postage-from-this/#findComment-1467225 Share on other sites More sharing options...
Solution roldahayes Posted January 31, 2014 Author Solution Share Posted January 31, 2014 Ok, This now makes sense and I can see where I am going wrong, The postage is added on the previous page so this particular page only has a complete basket total to work with.... I'll have to adjust the previous page to reduce the postage first. Thanks for the help on this. Quote Link to comment https://forums.phpfreaks.com/topic/285830-how-to-remove-postage-from-this/#findComment-1467227 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.