This guide will walk you through two tasks:
- Adding a pop-up confirmation when users attempt to change their payment method.
- Disallowing users from changing their default payment method on the "Account Details" page in WHMCS.
You can add a pop-up to confirm changes to the payment method using JavaScript. Here are the steps:
Locate the template file where the payment method dropdown is rendered. For invoices, it is usually in the viewinvoice.tpl file:
/templates/<your-template>/viewinvoice.tpl
In the template file, locate the paymentmethod dropdown. Add a script that triggers a confirmation dialog when the user attempts to change their payment method.
Example code:
<select name="gateway" id="paymentMethodDropdown" class="form-control">
{foreach from=$paymentmethods item=method}
<option value="{$method.sysname}"{if $method.sysname eq $defaultpaymentmethod} selected="selected"{/if}>{$method.name}</option>
{/foreach}
</select>
<script>
document.addEventListener('DOMContentLoaded', function () {
const dropdown = document.getElementById('paymentMethodDropdown');
dropdown.addEventListener('change', function (event) {
const confirmChange = confirm('{$LANG.paymentmethod}');
if (!confirmChange) {
// Reset to previous value if the user cancels
dropdown.value = dropdown.getAttribute('data-default');
} else {
dropdown.setAttribute('data-default', dropdown.value);
}
});
// Set initial default value
dropdown.setAttribute('data-default', dropdown.value);
});
</script>Make sure the language key $LANG.paymentmethod is updated or created in your WHMCS language override file.
- Navigate to your WHMCS installation path:
whmcsinstallationpath/lang/override/ - Open or create the appropriate language file for your default language (e.g.,
english.php). - Add or update the following entry:
$_LANG['paymentmethod'] = 'Changing your payment method may cause delays. Do you want to proceed?';You can choose to customize the text or add a new language key. Just ensure it is saved in your language file.
After saving the template file, visit the invoice page and attempt to change the payment method. The pop-up should appear.
To disallow changes to the default payment method on the "Account Details" page, you can either disable the dropdown entirely or enforce restrictions using hooks.
Find the clientareadetails.tpl file:
/templates/<your-template>/clientareadetails.tpl
Locate the section rendering the payment method dropdown and disable it:
<div class="form-group">
<label for="inputPaymentMethod" class="control-label">{$LANG.paymentmethod}</label>
<select name="paymentmethod" id="inputPaymentMethod" class="form-control" disabled>
<option value="{$defaultpaymentmethod}" selected="selected">[{$LANG.paymentmethoddefault}]</option>
{foreach from=$paymentmethods item=method}
<option value="{$method.sysname}"{if $method.sysname eq $defaultpaymentmethod} selected="selected"{/if}>{$method.name}</option>
{/foreach}
</select>
<input type="hidden" name="paymentmethod" value="{$defaultpaymentmethod}" />
</div>This disables the dropdown and ensures the default payment method is retained.
By following these steps, you can:
- Add a confirmation pop-up for changing payment methods.
- Disallow changes to the default payment method on the "Account Details" page.
These changes enhance the reliability and security of payment configurations in WHMCS. If you have any questions or run into issues, feel free to contact support or leave a comment.