I am facing one problem.I don't know either this is possible in magento (default way ) or i have to create my custom module for it. I have scenario where after entering shipping details customer will be redirected to specific shipping method on the basis of his city and country.

Shipping methods will be three (For Newyork,For USA,Other countries) Like if he belongs to Newyork and country is USA .He got these options 1) For Newyork one day $5.

2) For USA $10 etc but if he is not from Newyork but other city of USA Than he gots different options and same condition for if he doesn't belongs to USA he gots other options.I have studied the Flates rates but i think that didn't fulfill my requirements.Any advice or guidness will be helpful.Thanks

1 Answer 1


Here is how I would do it.
I would create my own shipping module (or 3 of them if you want to keep things separate). Follow this tutorial.

In the collectRates method of the module you can add you code that decides what the price should be for shipping depending on the address.
The method receives a parameter called $request. You can access the address values from this parameter:

  • $request->getDestCountryId() - for country
  • $request->getDestCity() - for city name
  • $request->getDestRegionId() - for region id

So you can do something like this:

if ($request->getDestCountryId() == 'US' && in_array(strtolower($request->getDestCity()), array('newyork', 'new york'))){ //for new york
    $price = 5;
elseif ($request->getDestCountryId() == 'US'){ //for the rest of the US
    $price = 10;
else{//for the rest of the world
   $price = ...//your price here.

Then add this price to the method:


If you take the approach with 3 shipping modules, the code above will be split among the 3 modules and instead of defining a price on the branch that does not match the module conditions just return false.

Note: This is just a proof of concept. Don't hard-code the values. You may want to fill them in the system->configuration panel. Also this code is not tested it may have errors in it.

I just read the question more carefully and I think you can achieve this with table rates.

Country|Region/State|Zip/Postal Code|Weight (and above)|Shipping Price
US     |New York    |*              |0                 |5
US     |*           |*              |0                 |10
*      |*           |*              |0                 |YOUR PRICE HERE

But this means that for the entire New York region (not only the city) you will have the same price (5).
I would still use the method described above because it give you more control over what happens.

  • Does this method shows three options if customer belongs to Newyork like (option 1) Newyork $5,option 2) USA $10 option 3) Others $20.I want to show three options for each option(Newyork,USA,Others).These options will be different for each one.Hopes you got my point. Oct 22, 2013 at 7:23
  • I'm not sure I get the full picture, but the method I described can be manipulated into showing how many options you want. Follow the tutorial and create a different method for each option. The use $result->append($method); for each option.
    – Marius
    Oct 22, 2013 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.