Forum Moderators: coopster & phranque

Message Too Old, No Replies

Setup shipping fees by continent

Define the shipping fees upon the continent where the items will be sent.

         

JilJones

6:46 pm on Aug 23, 2004 (gmt 0)

10+ Year Member



Hello,

I have a shopping cart and I'd like to define the shipping fees upon the continent (US-Canada / Europe / Other countries), where the items will be sent (USA = US, CA / EUR = AT, BE, BG, CZ, DK, EE * plus all the European countries / OTH = all the other countries, not listed above).

The code below works if I charge by country, but that means I have to enter the code for all the countries (not all are listed below) in the sub custom_shipping, which is a lot of lines of code.

I though to group the countries by continent, and define for each country to which continent it belongs, so instead of having $Ship_Country eq US, I could have $Ship_Continent eq EUR.

But I don't know exactly how to start… Does any one could help me and tell me how to do that?

Thanks a lot for your precious help!

Jil


sub custom_shipping
{
if ($Ship_Country eq US) {
$shipping_total = 9.00;
} elsif ($Ship_Country eq FR) {
$shipping_total = 19.00;
} else {
$shipping_total = 49.00;
}
}

sub country
{
local ($field);

%country_array =('USA', 'US',
'France', 'FR',
'Germany', 'GE',
'Ecuador','EC',
'Egypt','EG',
'El Salvador','SV',
'Equitorial Guinea','GQ',
'Eritrea','ER',
'Estonia','EE',
'Ethiopia','ET',
'Zimbabwe','ZW');

foreach $field ( sort ( keys %country_array ) )
{
if ($Bill_Country eq $country_array{$field})
{
$Bill_Country_Value = $field;
$Bill_Country_ABR = $country_array{$field};
}
if ($Ship_Country eq $country_array{$field})
{
$Ship_Country_Value = $field;
$Ship_Country_ABR = $country_array{$field};
}

if ($country_array{$field} eq $default_country && $Bill_Country eq "")
{
$bill_countries .= "<option selected value=\"$country_array{$field}\">$field</option>\n";
} else {
$bill_countries .= "<option value=\"$country_array{$field}\">$field</option>\n";
}
$ship_countries .= "<option value=\"$country_array{$field}\">$field</option>\n";
}

}

jatar_k

9:06 pm on Aug 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld JilJones,

I would use a db for driving something like that so that you could then just select the fee for the country you need.

hmm, I looked at your post when you posted it and have been rolling it around in my head off and on. I don't seem to be able to quite see the way to go about it.

Do you only have the country to work with? or could you somehow find out the continent before you get to this point?

Maybe a function that gets the continent by comparing the given country to your arrays of countries per continent. You could then have a very simple function to do fee by cointinent.

That make any sense?

JilJones

10:04 am on Aug 26, 2004 (gmt 0)

10+ Year Member



Dear Jatar,

Thank you for your feedback.

Finally I figured it out differently, and left the idea to define it by continents. As there were not too many Europeans countries, I preferred to define all of them in the sub custom_shipping.

Thanks