Hiding NS1 and NS2 Fields in WHMCS for Server/VPS Signups

Hiding NS1 and NS2 Fields in WHMCS for Server/VPS Signups

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.

Transform Your Business with Our New Unlimited Plan

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.

				
					<?php

add_hook('ShoppingCartConfigureProductAddonsOutput', 1, function($vars) {
    add_hook('ClientAreaFooterOutput', 1, function($vars) {
        return "
            <script>
                jQuery(document).ready(function() {
                    jQuery.each([ 'inputNs1prefix', 'inputNs2prefix' ], function(index, value) {
                        jQuery('#' + value).val('ns' + (index + 1)).parent().hide();
                    });
                });
            </script>
        ";
    });
});

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 "
            <script>
                jQuery(document).ready(function() {
                    jQuery.each([ 'inputNs1prefix', 'inputNs2prefix' ], function(index, value) {
                        jQuery('#' + value).val('ns' + (index + 1)).parent().hide();
                    });
                });
            </script>
        ";
    });
});

				
			

This portion of the code performs the following actions:

  1. Adding a Nested Hook: The ShoppingCartConfigureProductAddonsOutput hook adds another hook, ClientAreaFooterOutput, to the client area footer.
  2. 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 and ns2 respectively and hides their parent elements using parent().hide().
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:

  1. Checking the URL Parameters: It verifies if the a parameter is confproduct and if the i parameter is either not empty or equal to 0.
  2. Setting NS1 and NS2 Prefixes: If the conditions are met, it returns an array setting the ns1prefix and ns2prefix values to ns1 and ns2, respectively.

Implementation Steps

  1. Create the Hook File: Save the provided PHP code as ns_hook.php.
  2. Upload the Hook File: Place the ns_hook.php file in the includes/hooks directory of your WHMCS installation.
  3. 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

author avatar
averagejoe

Post Your Comment

hostiko-success-icon6

Professional-Grade Hosting for Organizations with High Security Standards.

Contact Info

Address:

30 N Gould St Ste R
Sheridan, WY 82801

210 Jones St, Door B
Dubuque, IA 52001

Email:

Phone:

en_USEnglish

Unlock Hosting Secrets!

Sign up now to get our Small Business Unlimited Hosting Booklet. Discover why Average Joe’s Hosting is your only choice to maximize your online presence and boost your business efficiency.

Didn't Find The Perfect Hosting Package?

Let's have a chat

We GUARANTEE we can beat your current hosting service provider's price!