Jump to content

Client registration currency hook


nitaish

Recommended Posts

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 by nitaish
Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated