MrNickRegan Posted September 14, 2014 Share Posted September 14, 2014 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 More sharing options...
markg-uk Posted September 15, 2014 Share Posted September 15, 2014 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 More sharing options...
burt Posted September 15, 2014 Share Posted September 15, 2014 Or... maek a bunch of new zones and inside those zones put the relevant delivery countries. now assign the relevant zone to the relevant shipping module Link to comment Share on other sites More sharing options...
MrNickRegan Posted September 16, 2014 Author Share Posted September 16, 2014 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 More sharing options...
markg-uk Posted September 16, 2014 Share Posted September 16, 2014 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 More sharing options...
MrNickRegan Posted September 16, 2014 Author Share Posted September 16, 2014 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 More sharing options...
MrNickRegan Posted September 17, 2014 Author Share Posted September 17, 2014 @@markg-uk any ideas? Could it be that I need to insert the code after the constructor and create a constructor to define the logic? Any help with this would be hugely appreciated! Kind Regards Nick Link to comment Share on other sites More sharing options...
markg-uk Posted September 18, 2014 Share Posted September 18, 2014 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 More sharing options...
burt Posted September 18, 2014 Share Posted September 18, 2014 @@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 More sharing options...
MrNickRegan Posted September 18, 2014 Author Share Posted September 18, 2014 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 More sharing options...
markg-uk Posted September 22, 2014 Share Posted September 22, 2014 For the opposite, the code should be something like this: global $order; if ($order->delivery['country']['iso_code_2'] == 'GB') { $this->enabled = false; } You did put the double equals sign right? Link to comment Share on other sites More sharing options...
MrNickRegan Posted September 23, 2014 Author Share Posted September 23, 2014 @@markg-uk That works perfectly! Many thanks! It was indeed the double equals that I was missing! I really appreciate all your help with this one!! :) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.