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

前端 未结 1 1090
忘了有多久
忘了有多久 2021-01-17 00:56

Hi stack i have one issue that dont know how to resolve. I want to show Dedicated IP from customer order to show like this:

I make a short check, and found

相关标签:
1条回答
  • 2021-01-17 01:35

    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}
    
    0 讨论(0)
提交回复
热议问题