Display Dedicated IP into viewinvoice.tpl and invoicepdf.tpl in WHMCS?

一曲冷凌霜 提交于 2019-12-01 14:00:34

Create php file in whmcs_dir/includes/hooks/ (say: dedicated_ip.php) and add the following code:

<?php
use WHMCS\Database\Capsule as DB;
add_hook('ClientAreaPageViewInvoice', 1, function($vars) { 
    $dedicatedIps = [];

    foreach ($vars['invoiceitems'] as $k => $item) {
        $ip = '';
        if ($item['type'] == 'Hosting') {
            $hosting = DB::table('tblhosting')->select('dedicatedip')->where('id', $item['relid'])->first();
            if (!is_null($hosting)) {
                $ip = $hosting->dedicatedip;
            }
        } 
        $dedicatedIps[$k] = $ip;

    }
    return ['dedicatedIps' => $dedicatedIps];
});

This code will run only in the invoice view page, and adds an array of dedicated IPs for each invoice items. Domains for example will have empty ip.

Then in viewinvoice.tpl update the invoice items loop as following:

{foreach from=$invoiceitems item=item key=key}
    <tr>
        <td>
        {$item.description}{if $item.taxed eq "true"} *{/if}
        {if $key|in_array:$dedicatedIps}
        <br>IP: {$dedicatedIps[$key]}

        {/if}
        </td>
        <td class="text-center">{$item.amount}</td>
    </tr>
{/foreach}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!