if that's your first thought, think again! eventually, and I imagine almost certainly in WHMCS v8 next year, the use of {php} will be prevented, so it may be best to get out of the habit and only use it as an absolute last resort (and even then, only temporarily).
just a personal choice, but where possible I try not to use the API for things like this, as often in new releases certain API functions don't work and you're then left waiting for WHMCS to fix them... so for something as basic as this, i'd just query the db in an action hook.
take a look at sentq's hook in the thread below as a starting point...
https://forums.whmcs.com/showthread.php?115218-Custom-Link-in-complete-tpl-Template
I would imagine for you, the query would need changing to...
$getService = Capsule::table("tblhosting")->where("orderid", $params['orderid'])->wherein("packageid",[1,2,3])->take(1);
i'm slightly cheating here as i'm searching if the order contains product IDs 1,2,3 (replace with the Ids in productgroup 5) - tblhosting doesn't contain product groups IDs for the ordered products, you'd have to join with tblproducts to find the group ID value for a product... that would be the thorough way to do it with a join, and i'm sure you'd fine loads of examples of hooks with joins in in the forums posted by sentq and myself!
then it's just a case of changing the output in the hook to suit your requirements.