Jump to content

How to remove Postage from this


roldahayes
Go to solution Solved by roldahayes,

Recommended Posts

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?
Link to comment
Share on other sites

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 by davidannis
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.