You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.
Hi,
I need help on a shipping script by weight, each product has a weight, and each delivery area has a different price, and as the weight increases the delivery charge increases too, also i need to add half a kilo to the total weight for packaging, so far I have this but it is not working...
<?php // +-- // | All custom shipping scripts work in the same way. A global // | variable named 'ecom.customship' contains the following PHP // | array. Array keys with value info: // | // | weight => Total weight of items being shipped. // | total => Subtotal of items being shipped. // | quantity => Quantity of items being shipped. // | stateprov => Ship to state/province. // | country => Ship to country. // | postalcode => Ship to postal code. // | rescom => Ship to residential/commercial status. // | shipstateprov => Ship origin state/province. // | shipcountry => Ship origin country. // | shipzip => Ship origin postal code. // | packages => An array containing all packages with // | each package defined in it's own array // | with keys: length, width, height, weight. // | delinfo => Delivery information array. // | delitems => An array containing all items with // | each item id as a key and the item quantity // | as a value. // | // | This script must set a global variable named // | 'ecom.customship_response' which is an array in the // | following format: // | // | method name => amount // | // | NOTE: Do not print anything within custom shipping // | scripts. They are designed only to return names and // | prices for custom shipping methods. // | // | This script is a Percentage of Total Item Cost script that // | returns a prices based on a percentage of the total item cost. // +-- $info = $this->globals('ecom.customship'); if (($info['country'] == 'UK - England & Wales')){ //England & Wales $method = 'Weight Shipping test to England & Wales'; $weight = $info['weight' + '0.50']; if ($weight >= 0.50 and $weight <= 15.99) { $total = '5.95'; } if ($weight >= 16.00 and $weight <= 16.99) { $total = '8.50'; } if ($weight >= 17.00 and $weight <= 17.99) { $total = '10.00'; } if ($weight >= 18.00 and $weight <= 18.99) { $total = '12.95'; } if ($weight > 19.00) { $method = 'Please contact us'; $total = '0.00'; } $custom = array($method => $total); } else { // Rest of the world $method = 'FOR SHIPPING COST CONTACT Westfield4Schools'; $total = '00.00'; $custom = array($method => $total); } $this->globals('ecom.customship_response',$custom); ?>
Cheers,
Bruce.
Offline
Try this:
<?php // +-- // | All custom shipping scripts work in the same way. A global // | variable named 'ecom.customship' contains the following PHP // | array. Array keys with value info: // | // | weight => Total weight of items being shipped. // | total => Subtotal of items being shipped. // | quantity => Quantity of items being shipped. // | stateprov => Ship to state/province. // | country => Ship to country. // | postalcode => Ship to postal code. // | rescom => Ship to residential/commercial status. // | shipstateprov => Ship origin state/province. // | shipcountry => Ship origin country. // | shipzip => Ship origin postal code. // | packages => An array containing all packages with // | each package defined in it's own array // | with keys: length, width, height, weight. // | delinfo => Delivery information array. // | delitems => An array containing all items with // | each item id as a key && the item quantity // | as a value. // | // | This script must set a global variable named // | 'ecom.customship_response' which is an array in the // | following format: // | // | method name => amount // | // | NOTE: Do not print anything within custom shipping // | scripts. They are designed only to return names && // | prices for custom shipping methods. // | // | This script is a Percentage of Total Item Cost script that // | returns a prices based on a percentage of the total item cost. // +-- $info = $this->globals('ecom.customship'); if ($info['country'] == 'UK - England & Wales') { //England & Wales $method = 'Weight Shipping test to England & Wales'; $weight = $info['weight'] + 0.5; if ($weight >= 0.50 && $weight <= 15.99) { $total = '5.95'; } if ($weight >= 16.00 && $weight <= 16.99) { $total = '8.50'; } if ($weight >= 17.00 && $weight <= 17.99) { $total = '10.00'; } if ($weight >= 18.00 && $weight <= 18.99) { $total = '12.95'; } if ($weight > 19.00) { $method = 'Please contact us'; $total = '0.00'; } $custom = array($method => $total); } else { // Rest of the world $method = 'FOR SHIPPING COST CONTACT Westfield4Schools'; $total = '0.00'; $custom = array($method => $total); } $this->globals('ecom.customship_response',$custom); ?>
Offline
Try this (a little cleaner, and handles all cases for weight):
<?php $info = $this->globals('ecom.customship'); // +-- // | UK - England & Wales // +-- if ($info['country'] == 'UK - England & Wales') { $weight = $info['weight'] + 0.5; if ($weight <= 15.99) {$total = '5.95'; $method = 'Shipping to England & Wales';} elseif ($weight <= 16.99) {$total = '8.50'; $method = 'Shipping to England & Wales';} elseif ($weight <= 17.99) {$total = '10.00'; $method = 'Shipping to England & Wales';} elseif ($weight <= 18.99) {$total = '12.95'; $method = 'Shipping to England & Wales';} else {$total = '0.00'; $method = 'FOR SHIPPING COST CONTACT Westfield4Schools';} // +-- // | Rest Of The World // +-- } else { $method = 'FOR SHIPPING COST CONTACT Westfield4Schools'; $total = '0.00'; } // End of if statement. $custom = array($method => $total); $this->globals('ecom.customship_response',$custom); ?>
Offline
Hi htw_Simon,
not quite... It now gives me £5.95 fine..thanks, but does not increase the shipping as I increase quantity... so still broken me thinks...
Cheers,
Bruce.
Offline
Hi,
Thanks Nick... It is still not pulling the cost for larger weights than the first weight break.. so ...when I add the weight to a product I add 0.149 for example... Will 3 decimal points effect the shipping sum or should I change all the weights to two decimal points, eg 0.50?
Cheers,
Bruce.
Offline
The script doesn't take in to account the quantity of items you have, just the weight. However, if you are increasing the quantity of items, and therefore the weight increases to the next cost bracket, it should give you a higher figure. If it is not increasing I would check the weights of the items that you are testing with.
As for product weights, I would be as accurate as possible. It won't matter that you have 3 decimal places or 2.
Offline
Hi,
OK when I add extra locations I have broken it again... Any Help?...
<?php $info = $this->globals('ecom.customship'); // +-- // | UK - England & Wales // +-- if ($info['country'] == 'UK - England & Wales') { $weight = $info['weight'] + 0.5; if ($weight <= 15.99) {$total = '5.95'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 16.99) {$total = '6.20'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 17.99) {$total = '6.50'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 18.99) {$total = '6.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 19.99) {$total = '7.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 20.99) {$total = '8.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 21.99) {$total = '9.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 22.99) {$total = '10.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 23.99) {$total = '11.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 24.99) {$total = '12.75'; $method = 'Shipping test to England & Wales';} else {$total = '0.00'; $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671';} $custom = array($method => $total); } // +-- // | UK - Scotland Lowlands // +-- elseif ($info['country'] == 'UK - Scotland Lowlands') { $weight = $info['weight'] + 0.5; if ($weight <= 15.99) {$total = '5.95'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 16.99) {$total = '6.20'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 17.99) {$total = '6.50'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 18.99) {$total = '6.75'; $method = 'Shipping test to Scotland Lowlands;} elseif ($weight <= 19.99) {$total = '7.75'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 20.99) {$total = '8.75'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 21.99) {$total = '9.75'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 22.99) {$total = '10.75'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 23.99) {$total = '11.75'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 24.99) {$total = '12.75'; $method = 'Shipping test to Scotland Lowlands';} else {$total = '0.00'; $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671';} $custom = array($method => $total); } // +-- // | UK - Scotland Highlands // +-- elseif ($info['country'] == 'UK - Scotland Highlands') { $weight = $info['weight'] + 0.5; if ($weight <= 15.99) {$total = '5.95'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 16.99) {$total = '6.20'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 17.99) {$total = '6.50'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 18.99) {$total = '6.75'; $method = 'Shipping test to Scotland Highlands;} elseif ($weight <= 19.99) {$total = '7.75'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 20.99) {$total = '8.75'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 21.99) {$total = '9.75'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 22.99) {$total = '10.75'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 23.99) {$total = '11.75'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 24.99) {$total = '12.75'; $method = 'Shipping test to Scotland Highlands';} else {$total = '0.00'; $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671';} $custom = array($method => $total); } // +-- // | Rest Of The World // +-- } else { $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671'; $total = '0.00'; $custom = array($method => $total); } // End of if statement. $this->globals('ecom.customship_response',$custom); ?>
Cheers,
Bruce.
Offline
You had 3 errors in your code.
<?php $info = $this->globals('ecom.customship'); // +-- // | UK - England & Wales // +-- if ($info['country'] == 'UK - England & Wales') { $weight = $info['weight'] + 0.5; if ($weight <= 15.99) {$total = '5.95'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 16.99) {$total = '6.20'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 17.99) {$total = '6.50'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 18.99) {$total = '6.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 19.99) {$total = '7.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 20.99) {$total = '8.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 21.99) {$total = '9.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 22.99) {$total = '10.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 23.99) {$total = '11.75'; $method = 'Shipping test to England & Wales';} elseif ($weight <= 24.99) {$total = '12.75'; $method = 'Shipping test to England & Wales';} else {$total = '0.00'; $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671';} $custom = array($method => $total); } // +-- // | UK - Scotland Lowlands // +-- elseif ($info['country'] == 'UK - Scotland Lowlands') { $weight = $info['weight'] + 0.5; if ($weight <= 15.99) {$total = '5.95'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 16.99) {$total = '6.20'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 17.99) {$total = '6.50'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 18.99) {$total = '6.75'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 19.99) {$total = '7.75'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 20.99) {$total = '8.75'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 21.99) {$total = '9.75'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 22.99) {$total = '10.75'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 23.99) {$total = '11.75'; $method = 'Shipping test to Scotland Lowlands';} elseif ($weight <= 24.99) {$total = '12.75'; $method = 'Shipping test to Scotland Lowlands';} else {$total = '0.00'; $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671';} $custom = array($method => $total); } // +-- // | UK - Scotland Highlands // +-- elseif ($info['country'] == 'UK - Scotland Highlands') { $weight = $info['weight'] + 0.5; if ($weight <= 15.99) {$total = '5.95'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 16.99) {$total = '6.20'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 17.99) {$total = '6.50'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 18.99) {$total = '6.75'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 19.99) {$total = '7.75'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 20.99) {$total = '8.75'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 21.99) {$total = '9.75'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 22.99) {$total = '10.75'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 23.99) {$total = '11.75'; $method = 'Shipping test to Scotland Highlands';} elseif ($weight <= 24.99) {$total = '12.75'; $method = 'Shipping test to Scotland Highlands';} else {$total = '0.00'; $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671';} $custom = array($method => $total); } // +-- // | Rest Of The World // +-- else { $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671'; $total = '0.00'; $custom = array($method => $total); } // End of if statement. $this->globals('ecom.customship_response',$custom); ?>
Offline
Hi,
So this script is not adding the + 0.5 bit.... any help...
<?php $info = $this->globals('ecom.customship'); // +-- // | UK - England & Wales // +-- if ($info['country'] == 'UK - England & Wales') { $weight = $info['weight'] + 0.5; if ($weight <= 5.00) {$total = '5.95'; $method = 'Weight Based Shipping to England & Wales';} elseif ($weight <= 9.99) {$total = '8.50'; $method = 'Weight Based Shipping to England & Wales';} elseif ($weight <= 14.99) {$total = '10.50'; $method = 'Weight Based Shipping to England & Wales';} elseif ($weight <= 24.99) {$total = '12.50'; $method = 'Weight Based Shipping to England & Wales';} elseif ($weight <= 34.99) {$total = '15.50'; $method = 'Weight Based Shipping to England & Wales';} elseif ($weight <= 44.99) {$total = '18.50'; $method = 'Weight Based Shipping to England & Wales';} elseif ($weight <= 54.99) {$total = '21.50'; $method = 'Weight Based Shipping to England & Wales';} elseif ($weight <= 64.99) {$total = '23.50'; $method = 'Weight Based Shipping to England & Wales';} else {$total = '0.00'; $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671';} $custom = array($method => $total); } // +-- // | UK - Scotland Lowlands // +-- elseif ($info['country'] == 'UK - Scotland Lowlands') { $weight = $info['weight'] + 0.5; if ($weight <= 5.00) {$total = '7.95'; $method = 'Weight Based Shipping to Scotland Lowlands';} elseif ($weight <= 9.99) {$total = '9.50'; $method = 'Weight Based Shipping to Scotland Lowlands';} elseif ($weight <= 14.99) {$total = '12.50'; $method = 'Weight Based Shipping to Scotland Lowlands';} elseif ($weight <= 24.99) {$total = '14.50'; $method = 'Weight Based Shipping to Scotland Lowlands';} elseif ($weight <= 34.99) {$total = '17.50'; $method = 'Weight Based Shipping to Scotland Lowlands';} elseif ($weight <= 44.99) {$total = '20.50'; $method = 'Weight Based Shipping to Scotland Lowlands';} elseif ($weight <= 54.99) {$total = '23.50'; $method = 'Weight Based Shipping to Scotland Lowlands';} elseif ($weight <= 64.99) {$total = '25.50'; $method = 'Weight Based Shipping to Scotland Lowlands';} else {$total = '0.00'; $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671';} $custom = array($method => $total); } // +-- // | UK - Scotland Highlands // +-- elseif ($info['country'] == 'UK - Scotland Highlands') { $weight = $info['weight'] + 0.5; if ($weight <= 5.00) {$total = '9.45'; $method = 'Weight Based Shipping to Scotland Highlands';} elseif ($weight <= 9.99) {$total = '12.00'; $method = 'Weight Based Shipping to Scotland Highlands';} elseif ($weight <= 14.99) {$total = '15.00'; $method = 'Weight Based Shipping to Scotland Highlands';} elseif ($weight <= 24.99) {$total = '17.00'; $method = 'Weight Based Shipping to Scotland Highlands';} elseif ($weight <= 34.99) {$total = '20.00'; $method = 'Weight Based Shipping to Scotland Highlands';} elseif ($weight <= 44.99) {$total = '23.00'; $method = 'Weight Based Shipping to Scotland Highlands';} elseif ($weight <= 54.99) {$total = '26.00'; $method = 'Weight Based Shipping to Scotland Highlands';} elseif ($weight <= 64.99) {$total = '28.00'; $method = 'Weight Based Shipping to Scotland Highlands';} else {$total = '0.00'; $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671';} $custom = array($method => $total); } // +-- // | Rest Of The World // +-- else { $method = 'FOR POSTAGE QUOTE, Contact Westfield4Schools on 0121 233 1671'; $total = '0.00'; $custom = array($method => $total); } // End of if statement. $this->globals('ecom.customship_response',$custom); ?>
Cheers,
Bruce.
Offline
Hi Nick,
after using this script for years is has just been brought to my attention that this bit is not working.....
$weight = $info['weight'] + 0.5;
is not adding the extra weight...
any thoughts?
Cheers,
Bruce.
Offline