nitaish Posted January 8, 2021 Share Posted January 8, 2021 (edited) Hello, We are trying to make a hook which will work on register.php if the Country is india the currency will show INR in the dropdown else USD and AUD. Our "if" condition is working fine but "else if" condition is not working. Can anyone help in correcting this code. <?php use WHMCS\Database\Capsule; function form_validation($vars) { if ($vars['templatefile']=='clientregister'){ $curriency = $vars['currencies']; $countrydropdown = $vars['clientcountriesdropdown']; $country = $vars['clientcountries']; $defaultcountry = $vars['defaultCountry']; $allowed['IN'] = ['INR']; $allowed['NOT-IN'] = ['USD','AUD']; if($defaultcountry == 'IN') { foreach ($curriency as $k => $item) { if (!in_array($item['code'],$allowed['IN'])) { unset($curriency[$k]); } } return array("currencies" => $curriency); } else if($defaultcountry != 'IN') { foreach ($curriency as $k => $item) { if (!in_array($item['code'], $allowed['NOT-IN'])) { unset($curriency[$k]); } } return array("currencies" => $curriency); } else{ return array("currencies" => $curriency); } } } add_hook("ClientAreaPageRegister", 1, "form_validation"); ?> Edited January 8, 2021 by nitaish 0 Quote Link to comment Share on other sites More sharing options...
string Posted January 8, 2021 Share Posted January 8, 2021 The default country value is not a dynamic value. It is configurated here: https://help.whmcs.com/m/localisation/l/678184-set-your-default-country-and-language To adjust the currency list after your client has changed the country, you would need to use javascript. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 8, 2021 Share Posted January 8, 2021 @string is right - virtually everyone who goes to your site will have India as their default country(if that's what you've set it as in general settings) - that value isn't controlled by the dropdown. to change it on the fly would be JavaScript, or I suppose you could use ClientAreaRegister, let them select whatever currency they want and then upon registration, update the client record with the currency that you think they should be using based on their client country... or use ClientDetailsValidation to throw an error message that currency X isn't an option if based in Y country and for them to choose currency Z instead. using the Geolcation hook might be another option to auto assign currencies to their locations - though there's no guarantees that identifying the location would be accurate. 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.