Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Showing zone shipping only for the shipping address


MrNickRegan

Recommended Posts

Hi All,

 

Once again I am in need of a little assistance that maybe someone could help me with?

 

I have made several copied of the Zones.php modules to allows for 4 different UK shipping costs and two international. All working fine however they all show in the checkout and ideally I would like to only show the shipping methods that relate to the customers country.

 

Can someone point me in the right direction?

 

Kind Regards

Nick

Link to comment
Share on other sites

Put something like this in the class constructor for the shipping module, effectively it disables the module unless the country that you want to ship to is listed:

 

Edit: the OR should be an AND of course!

if (($order->delivery['country']['iso_code_2'] != 'AL') OR ($order->delivery['country']['iso_code_2'] != 'AE'))    {
	 $this->enabled = false;
	 }
Link to comment
Share on other sites

Many thanks for your advice guys, I am however still having a little difficultly in getting this to work. If I understand correctly, what you are suggesting is:

 

 if the order delivery country = GB and order delivery country =GB - do not show shipping? 

 

should it be

 

if shipping country = GB and order delivery country = GB - Show shipping?

 

Sorry if this seems like a bit of a stupid question, I am still trying to get my head around PHP and how Oscommerce works.

Link to comment
Share on other sites

By default, a shipping module will show if its both enabled and is valid for the zone that is configured for (assuming that is setup)

 

For the UK only ones, if this is in the class constructor, it will disable that module unless the delivery country is UK:

if ($order->delivery['country']['iso_code_2'] != 'GB') { 
$this->enabled = false; 
}

I.e. if delivery country not equal to GB, this is disabled. Whether you do it as well for billing country isn't a coding issue.

 

Either this method of the one Burt mentioned will work.

Link to comment
Share on other sites

By default, a shipping module will show if its both enabled and is valid for the zone that is configured for (assuming that is setup)

 

For the UK only ones, if this is in the class constructor, it will disable that module unless the delivery country is UK:

if ($order->delivery['country']['iso_code_2'] != 'GB') { 
$this->enabled = false; 
}

I.e. if delivery country not equal to GB, this is disabled. Whether you do it as well for billing country isn't a coding issue.

 

Either this method of the one Burt mentioned will work.

 

Hi markg-uk

 

I have been playing around with this however with no luck. I have two dummy accounts that I have been using, one setup in Italy and the other in the UK. When I add this code to the constructor within zones.php it removes the shipping module from both accounts, flipping from false to true enables the module in both accounts. I am a little unsure as to where the issue lies as the logic seems reasonable. Any ideas?

 

Kind Regards

Nick 

Link to comment
Share on other sites

Sorry, just noticed this. I just remembered that you have to put this just after the function declaration so it can see the $order information:

global $order;

without it, that would mean it couldn't access the shipping country, making the logic be always true, hence it would always be disabled.

 

Try that. If no joy, copy and paste the whole shipping module and I'll test it on my shop

Link to comment
Share on other sites

@@MrNickRegan Why not try the way I mentioned?

 

It's slightly more work as you have to set up the relevant zones [ admin > location/taxes ], but it has to be better than hacking into the core code (eg if you wanted to update the shop version in the future, you have to remember all your hacks)..

Link to comment
Share on other sites

Hi @@markg-uk

 

That works perfectly for what I need, many thanks! 

 

to summarize i used the code below to enable only UK postage modules:

 

global $order;
if ($order->delivery['country']['iso_code_2'] != 'GB') { 
$this->enabled = false; 

 

@@burt I like your idea also however I already have a heavily modified version ... something I overlooked when I first started out unfortunately. I will in a few years most likely revamp my store with a new version but until then I am stuck with what I have.

 

Back on subject however I have two additional shipping modules that I would like to reverse the above logic on. i.e. if shipping address is not in the UK show shipping. I tried to add the array of countries however with no luck ... any clues?

 

Much appreciate all your help :)  

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...