Jump to content

Determine action based on country


mmcb

Recommended Posts

Here's the problem I'm facing.
I have an order form where people enter in there shipping details, easy enough. But what I want to happen is determine the cost of shipping based on where the user is from (ie. the country they enter).

Something like this:
if (strtoupper($Country) == "USA") {
      $Shipping = '1.00';
} else {
      $Shipping = '2.00';
}

The problem is is that people will enter varying forms of the one country (USA, US, United States, United States of America, etc). So how could I check for all the variations of country to determine what the shipping amount should be.

Cheers,
MMCB
Link to comment
https://forums.phpfreaks.com/topic/35054-determine-action-based-on-country/
Share on other sites

There is a much easier way, and this would be very fun to put together.

Take a list of all the countries (take you 20 minutes)

$countries = array(//all countries with pricing) // Example: usa=>1.00, asia=>2.00
Whatever you get the point of that part.

Now when you get ready to find out, echo out only the states, in a
<select>
foreach your countries array here to display the countries
</select>
Based on which one is picked, check the array for the price of that one, adn do what you need with it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.