veolio Posted April 9, 2023 Share Posted April 9, 2023 Hello, I am new to WHMCS and php and i would like to add a new custom php file that displays all the tlds and their pricing ... For that, i have created a new file : domainList.php under /public_html/ directory : domainList.php <?PHP $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.mysite.com/includes/api.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( array( 'action' => 'GetTLDPricing', // See https://developers.whmcs.com/api/authentication 'username' => 'GGT3m7EqO7bxnrb1HcT9i1z0tKOcmA03', 'password' => 'qRFYmqc7JDNprtGxFFwKBJzHyaGxMSbv', 'currencyid' => '1', 'responsetype' => 'json', ) ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); $jsonData = json_decode($response, true); add_hook('ClientAreaPage', 1, function($vars) { // Perform hook code here... return array("response" => $response); }); ?> i have added the part below so i can access the $response array in the domainList.tpl file add_hook('ClientAreaPage', 1, function($vars) { // Perform hook code here... return array("response" => $response); }); For now, i have some questions about my code : 1- Is my code structured the right way ? should i place it under the API/ directory ? 2 - If so, how can i access mysite.com/Domain-Listing.php and call the service domainList.php that is under the API directory ? 3- How can i set a template to this file (TPL file) ? ==> i saw some documentation here : https://developers.whmcs.com/advanced/creating-pages/ by using # Define the template filename to be used without the .tpl extension $ca->setTemplate('domainList'); 4- is the add_hook method used the right way to access $response array directly from the TPL file ? ==> In this case, i would do the following in the domainList.TPL file : {foreach $response['pricing'] as $tld => $price} {$tld} : {$price['register']['1']}<br> {/foreach} For your information, this is the result contained in the response variable : Thanks in advance for the help ! 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted April 11, 2023 Share Posted April 11, 2023 If you're building the code in the same directory as you WHMCS installation, use the local API instead. You just need to include the 'init.php' file. You should not place your files inside the api directory. There's documentation on how to create custom pages for WHMCS here: https://developers.whmcs.com/advanced/creating-pages/ The add_hook function can only be used as a hook. You can not run it in a custom page. Any hooks you create will need to be placed in /includes/hooks/. WHMCS also has data feeds that can provide you with product/domain pricing: https://docs.whmcs.com/Data_Feeds 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.