Katamaze Documentation

Auto-select country dropdown based on visitor’s location

The module can automatically select the value of country dropdown for visitors based on their location. For example if a visitor is registering on your WHMCS from Italy, the module automatically selects Italy in the dropdown.

If you want to enable this feature you have to edit 2 template files of your WHMCS.

Warning

Please notice that in order to complete these steps, a basic knowledge of Smarty is required and that some templates, especially the older ones, are not supported.

First of all open your {YOUR_TEMPLATE}/clientregister.tpl and look for this section of code:

Find Country dropdown

<select id="country" name="country" class="form-control">
    {foreach $clientcountries as $countryCode => $countryName}
        <option value="{$countryCode}"{if (!$clientcountry && $countryCode eq $defaultCountry) || ($countryCode eq $clientcountry)} selected="selected"{/if}>
            {$countryName}
        </option>
    {/foreach}
</select>

Keep in mind that the code could be a bit different. You simply have to change if statement above highlighted in red like follows (changes are highlighted in blue).

Copy the following If statement

{if (!$clientcountry && !$al_country && $countryCode eq $defaultCountry) || ($countryCode eq $clientcountry) || (!$clientcountry AND $countryCode eq $al_country)}

The result should look like follows:

Result

<select id="country" name="country" class="form-control">
    {foreach $clientcountries as $countryCode => $countryName}
        <option value="{$countryCode}"{if (!$clientcountry && !$al_country && $countryCode eq $defaultCountry) || ($countryCode eq $clientcountry) || (!$clientcountry AND $countryCode eq $al_country)}>
            {$countryName}
        </option>
    {/foreach}
</select>

Now open your {YOUR_ORDERFORM}/viewcart.tpl and look for this section of code:

Find Country dropdown

<select id="country" name="country" class="form-control">
    {foreach from=$countries key=thisCountryCode item=thisCountryName}
        <option value="{$thisCountryCode}" {if $thisCountryCode eq $clientsdetails.country}selected="selected"{/if}>{$thisCountryName}</option>
    {/foreach}
</select>

Keep in mind that also in this case the code could be a bit different. You have to replace the if statement highlighted above with the following one:

Copy the following If statement

{if $thisCountryCode eq $al_country} selected="selected"{/if}

The result should look like follows:

Result

<select id="country" name="country" class="form-control">
    {foreach from=$countries key=thisCountryCode item=thisCountryName}
        <option value="{$thisCountryCode}"{if $thisCountryCode eq $al_country} selected="selected"{/if}>{$thisCountryName}</option>
    {/foreach}
</select>

On some templates the select that contains the list of countries is not generated in a foreach loop. The list could be incorporated in a built-in variable like {$clientcountriesdropdown}. In this case simply add replace modifier as follows:

Source Code Title

{$clientcountriesdropdown|replace:'selected="selected"':''|replace:"value=\"$al_country\"":"value=\"$al_country\" selected=\"selected\""}

Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Module upgrade
Viewed 1375 times since Mon, Mar 21, 2016
Introduction to multi-brand billing
Viewed 1438 times since Mon, May 9, 2016