akust0m Posted July 1, 2018 Share Posted July 1, 2018 Hi there, I'd like to only allow one country option instead of all of the country options available in 'includes/countries.php'. I'd prefer a way to adjust this that will survive WHMCS updates. Is there a way to adjust the $countries array via a hook? Which hook point would I need to attach it to? Thanks! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 1, 2018 Share Posted July 1, 2018 14 minutes ago, akust0m said: I'd like to only allow one country option instead of all of the country options available in 'includes/countries.php'. if you're using v7 or later then that file is no longer used... https://docs.whmcs.com/Customising_Countries_and_Calling_Codes#Removing_a_Country 15 minutes ago, akust0m said: I'd prefer a way to adjust this that will survive WHMCS updates. the above method should do that. 15 minutes ago, akust0m said: Is there a way to adjust the $countries array via a hook? Which hook point would I need to attach it to? I daresay you could if you had to, but the above method would be simpler. 0 Quote Link to comment Share on other sites More sharing options...
akust0m Posted July 1, 2018 Author Share Posted July 1, 2018 Thanks @brian! Would be good if there was a way to specify the one country I want to allow instead disabling all-1. Oh well 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 1, 2018 Share Posted July 1, 2018 1 hour ago, akust0m said: Would be good if there was a way to specify the one country I want to allow instead disabling all-1. instinctively, I think the safer method (e.g don't give WHMCS a reason to go wrong lol) would be to remove them as per above... but I can see that would be time-consuming, so if you really want to hardcode the countries array just to be one (or more) countries, then you could use the following hook... <?php /** * Only Allow Specific Countries During Cart Ordering / Registration * @author brian! */ function cart_only_allow_specific_countries($vars) { $allowed = ['United Kingdom']; if ($vars['templatefile']=='viewcart'){ $countries = $vars['countries']; } elseif ($vars['templatefile']=='clientregister'){ $countries = $vars['clientcountries']; } foreach ($countries as $k => $country) { if (!in_array($country,$allowed)) { unset($countries[$k]); } } if ($vars['templatefile']=='viewcart'){ return array("countries" => $countries); } elseif ($vars['templatefile']=='clientregister'){ return array("clientcountries" => $countries); } } add_hook("ClientAreaPage", 1, "cart_only_allow_specific_countries"); so the above will code the checkout / registration pages to remove countries other than "United Kingdom"... I suppose you could pull the allowed country from your localisation -> default country value instead of declaring it in the hook, but with no idea what you want to use this for, I just declared it as an array in the hook... also, you might need to expand it for the clientregister page, but that is just a HTML string variable not an array (unlike the other two pages), so you could just code the string in the hook and return it... the complicating factor would be if the client current stored country value was different from the "allowed" country value and then that get more complicated - you could check in the hook for that (it's a basic if statement), but there's no point in coding that unless it becomes necessary. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.