Bro you have to include the below provided code at the top of your hook file
use WHMCS\Database\Capsule;
The full code block for the hook will be,
<?php
use WHMCS\Database\Capsule;
add_hook('ShoppingCartCheckoutCompletePage', 1, function($vars) {
$ordernumber = $vars['ordernumber'];
$orderid = $vars['orderid'];
$invoiceid = $vars['invoiceid'];
$productid = Capsule::table('tblinvoiceitems')
->join('tblhosting', 'tblinvoiceitems.relid', '=', 'tblhosting.id')
->where('tblinvoiceitems.invoiceid','=', $invoiceid)
->where('tblinvoiceitems.type', '=', 'Hosting')
->select('tblhosting.packageid')
->get();
return $productid;
});
And you can get the productid in the tpl using json_decode. An example is provided below
{foreach $addons_html as $addon_html}
<div class="order-confirmation-addon-output">
{$array = json_decode($addon_html,1)}
{foreach $array as $key=>$item}
{if $key == 0}
<p>{$item['packageid']}</p>
{/if}
{/foreach}
</div>
{/foreach}