Hiding NS1 and NS2 Fields in WHMCS for Server/VPS Signups
- By averagejoe
When setting up a Server or VPS in WHMCS, clients are often presented with fields for entering NS1 and NS2 prefixes during the signup process. However, there are scenarios where you might want to hide these fields to streamline the user experience.
When setting up a Server or VPS in WHMCS, clients are often presented with fields for entering NS1 and NS2 prefixes during the signup process. However, there are scenarios where you might want to hide these fields to streamline the user experience. This can be achieved using a custom WHMCS hook. Below, we delve into the technical details of a PHP script designed to accomplish this task.
Understanding the Hook Code
The following hook script, ns_hook.php
, hides the NS1 and NS2 input fields from the client area when configuring a Server/VPS product in WHMCS.
jQuery(document).ready(function() {
jQuery.each([ 'inputNs1prefix', 'inputNs2prefix' ], function(index, value) {
jQuery('#' + value).val('ns' + (index + 1)).parent().hide();
});
});
";
});
});
add_hook('ClientAreaPageCart', 1, function($vars) {
if ($_GET['a'] === 'confproduct' AND (!empty($_GET['i']) || $_GET['i'] === '0')) {
return array (
'server' => array (
'ns1prefix' => 'ns1',
'ns2prefix' => 'ns2'
)
);
}
});
?>
Breakdown of the Code
Hook 1: ShoppingCartConfigureProductAddonsOutput
add_hook('ShoppingCartConfigureProductAddonsOutput', 1, function($vars) {
add_hook('ClientAreaFooterOutput', 1, function($vars) {
return "
";
});
});
This portion of the code performs the following actions:
- Adding a Nested Hook: The
ShoppingCartConfigureProductAddonsOutput
hook adds another hook,ClientAreaFooterOutput
, to the client area footer. - Injecting JavaScript: The
ClientAreaFooterOutput
hook returns a script that:- Waits for the document to be fully loaded using
jQuery(document).ready
. - Iterates over the NS1 and NS2 input fields (
inputNs1prefix
,inputNs2prefix
). - Sets the value of these fields to
ns1
andns2
respectively and hides their parent elements usingparent().hide()
.
- Waits for the document to be fully loaded using
Hook 2: ClientAreaPageCart
add_hook('ClientAreaPageCart', 1, function($vars) {
if ($_GET['a'] === 'confproduct' AND (!empty($_GET['i']) || $_GET['i'] === '0')) {
return array (
'server' => array (
'ns1prefix' => 'ns1',
'ns2prefix' => 'ns2'
)
);
}
});
This hook focuses on ensuring that when a user configures a product, the NS1 and NS2 prefixes are set correctly:
- Checking the URL Parameters: It verifies if the
a
parameter isconfproduct
and if thei
parameter is either not empty or equal to0
. - Setting NS1 and NS2 Prefixes: If the conditions are met, it returns an array setting the
ns1prefix
andns2prefix
values tons1
andns2
, respectively.
Implementation Steps
- Create the Hook File: Save the provided PHP code as
ns_hook.php
. - Upload the Hook File: Place the
ns_hook.php
file in theincludes/hooks
directory of your WHMCS installation. - Clear Template Cache: Ensure to clear the template cache in WHMCS to apply the changes.
By implementing this hook, you can seamlessly hide the NS1 and NS2 input fields during the Server/VPS signup process in WHMCS. This customization helps to simplify the client experience by automatically handling the NS prefix values in the background.
For further customization or more advanced use cases, you can expand this script to fit your specific needs. Understanding and leveraging WHMCS hooks can significantly enhance the flexibility and functionality of your WHMCS setup.
Connect with Us
For more tips, tutorials, and hosting solutions, visit our website at Average Joe’s Hosting. Follow us on social media for the latest updates:
#WHMCS #WebHosting #ServerSetup #VPSHosting #TechTips #WebDevelopment #HostingSolutions #AverageJoesHosting #PHP #WebHostingTips #ServerManagement #WebHostingCompany