JoAnne_B Posted August 11, 2009 Share Posted August 11, 2009 Hello. I've been asked to update what I thought would be an easy edit "buy now button" job for a client that uses paypal. I was asked to edit pricing and shipping costs. Logged into paypal to find no buttons have been created! I found on their server a cdtable.php file where I was able to edit product pricing without a problem and it is working. However, shipping.. I'm lost! Right now cart is set up for shipping up to 4 items only. Client would like to add $10.35 for 5-30 products ordered and $13.95 for 30-50 products ordered. Anything above that buyer will have to contact seller. Here is the code: <?php $shipping[0] = 4.95; $ship_cutoff = 4; $shipping[1] = $shipping[0]*2; Could someone help me with this please? How do I add the additional shipping costs? Thanks a bunch! JoAnne Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 11, 2009 Share Posted August 11, 2009 Try: <?php $ship_min= 5; $ship_max = 29; $ship_minone=31; $ship_maxone=50; if(range($ship_min) && range($ship_max)) { $shipping[0] = 10.35;} if(range($ship_minone) && range($shipmax_one)){ $shipping[0] = 13.95;} $shipping[1] = $shipping[0]*2; ?> Quote Link to comment Share on other sites More sharing options...
JoAnne_B Posted August 11, 2009 Author Share Posted August 11, 2009 Thank again... but what about shipping for 1-4 items at $4.95. I just copied the code and added that in there to see if it would be correct, but got an error when I attempted to post... grrr Could this be correct? <?php $ship_min= 1; $ship_max = 4; $ship_minone= 5; $ship_maxone = 30; $ship_mintwo=31; $ship_maxtwo=50; if(range($ship_min) && range($ship_max)) { $shipping[0] = 4.95;} if(range($ship_minone) && range($shipmax_one)){ $shipping[0] = 10.35;} if(range($ship_mintwo) && range($shipmax_two)){ $shipping[0] = 13.95;} $shipping[1] = $shipping[0]*2; ?> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 11, 2009 Share Posted August 11, 2009 whats the error? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 11, 2009 Share Posted August 11, 2009 Updated: <?php $ship_min= 5; $ship_max = 29; $ship_minone=31; $ship_maxone=50; if($ship_min =>5 && $ship_max <=29) { $shipping[0] = 10.35;} if($ship_minone =>31 && $ship_maxone <=50){ $shipping[0] = 13.95;} $shipping[1] = $shipping[0]*2; ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 11, 2009 Share Posted August 11, 2009 I'm having a problem understanding your variables? Whar variable represents the quantity? Also, what is the difference between $shipping[0] and $shipping[1] This should be a simple problem (I'll use $quantity to represent the quantity) if ($quantity <= 4) { $shipping[0] = 4.95 } elseif ($quantity <= 15) { $shipping[0] = 10.35 } elseif ($quantity <= 30) { $shipping[0] = 13.95 } else { //Contact seller } Edit, your original post states the seller want to "add" those costs for the larger quantities. If that means that 5-15 units will be (4.95 + 10.35) and 16-30 units will be (4.95 + 10.35 + 13.95), then just change the $shipping[0] = xxx; to shipping[0] += xxx; on the additional quantities lines Quote Link to comment Share on other sites More sharing options...
JoAnne_B Posted August 12, 2009 Author Share Posted August 12, 2009 When I use this code I get the following error.. $ship_min= 1; $ship_max = 4; $ship_minone= 5; $ship_maxone = 30; $ship_mintwo=31; $ship_maxtwo=50; if(range($ship_min) && range($ship_max)) { $shipping[0] = 4.95;} if(range($ship_minone) && range($shipmax_one)){ $shipping[0] = 10.35;} if(range($ship_mintwo) && range($shipmax_two)){ $shipping[0] = 13.95;} $shipping[1] = $shipping[0]*2; Error Received: Warning: range() expects at least 2 parameters, 1 given in /data/16/0/124/85/776737/user/795141/htdocs/incFiles/cdtable.php on line 9 Warning: range() expects at least 2 parameters, 1 given in /data/16/0/124/85/776737/user/795141/htdocs/incFiles/cdtable.php on line 11 Warning: range() expects at least 2 parameters, 1 given in /data/16/0/124/85/776737/user/795141/htdocs/incFiles/cdtable.php on line 13 When I use this code I get... if ($quantity <= 4) { this is line 3 $shipping[0] = 4.95 } elseif ($quantity <= 15) { $shipping[0] = 10.35 } elseif ($quantity <= 30) { $shipping[0] = 13.95 } else { //Contact seller } Error Received: Parse error: syntax error, unexpected '<' in /data/16/0/124/85/776737/user/795141/htdocs/incFiles/cdtable.php on line 3 We are selling CDs. When someone purchases 1-4 CD's, shipping costs $4.95 When someone purchases 5-29 CD's, shipping is $10.35 When someone purchses 30-50 CD's, shipping cost is $13.95 If customer wants to purchase more than 50 CDs, they contact seller. Hmmm... now what? Thanks again! Jo Quote Link to comment Share on other sites More sharing options...
Philip Posted August 12, 2009 Share Posted August 12, 2009 range() expects at least 2 parameters, 1 given Tells you a lot about what is wrong! But range probably isn't what you're looking for anyways - since it returns an array of values, and not checking to see if a value is in that range. What are the first 2 lines of the if/elseif way? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 12, 2009 Share Posted August 12, 2009 I would use a switch statement to figure out the shipping amount: <?php $shipping[0] = -1; switch(true) { case ($quantity > 0 && $quantity < 5): $shipping[0] = 4.95; break; case ($a quantity > 5 && $quantity < 30): $shipping[0] = 10.35; break; case ($quantity > 29 && $quantity < 51): $shipping[0] = 13.95; break; case ($quantity > 50): $shipping[0] = -1; break; } if ($shipping[0] > 0) echo 'For ' . quantity . ' products, shipping will be $' . $shipping[0] . "\n"; else echo "Please contact the supplier\n"; ?> Ken Quote Link to comment Share on other sites More sharing options...
JoAnne_B Posted August 13, 2009 Author Share Posted August 13, 2009 Man, I'm getting closer with each suggestion... thank you Using the following code I have no shipping price included in the shopping cart once the add to cart is clicked... also, "please contact the supplier" is displayed as simple text at the very top of the page. I changed quantity on in the cart on item purchased to 6, 15, etc. to test each. I also had to remove the "a and space) in the line for <30 items as I previously received a syntax error, unexpected T_string in that line. $shipping[0] = -1; switch(true) { case ($quantity > 0 && $quantity < 5): $shipping[0] = 4.95; break; case ($a quantity > 5 && $quantity < 30): $shipping[0] = 10.35; break; case ($quantity > 29 && $quantity < 51): $shipping[0] = 13.95; break; case ($quantity > 50): $shipping[0] = -1; break; } if ($shipping[0] > 0) echo 'For ' . quantity . ' products, shipping will be $' . $shipping[0] . "\n"; else echo "Please contact the supplier\n"; Whatcha think? FYI: After the code for shipping on this cdtable.php file is code for the products to be displayed. $products = array( ..... etc. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 13, 2009 Share Posted August 13, 2009 corrected obvious syntax errors: <?php $shipping[0] = -1; switch(true) { case ($quantity > 0 && $quantity < 5): $shipping[0] = 4.95; break; case ($quantity > 5 && $quantity < 30): $shipping[0] = 10.35; break; case ($quantity > 29 && $quantity < 51): $shipping[0] = 13.95; break; case ($quantity > 50): $shipping[0] = -1; break; } if ($shipping[0] > 0) echo 'For ' . $quantity . ' products, shipping will be $' . $shipping[0] . "\n"; else echo "Please contact the supplier\n"; ?> Quote Link to comment 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.