Jump to content

Fetch data from the table and insert in the email template.


fabianbur

Recommended Posts

I suppose this is simple, but it is making my life difficult.

I need in "Invoice Payment Confirmation" Include a value from authdata field of tblclients table.

Here I have searched and maybe something similar to this hook is the way

<?php

use WHMCS\Database\Capsule;

add_hook('EmailPreSend', 1, function($vars)
{
    if (in_array($vars['messagename'], array('Invoice Payment Confirmation')))
    {
        $codigopay = Capsule::select(Capsule::raw('SELECT authdata FROM tblclients WHERE id = "' . $vars['relid'] . '"));

        foreach ($codigopay as $v)
        {
            $merge_fields['code_payme'][] = $v->authdata;
        }

        return $merge_fields;
    }
});

Thank you very much for the help.

 

Link to comment
Share on other sites

This seems easier, but it still doesn't work

<?php
use WHMCS\Database\Capsule;

add_hook("EmailPreSend", 1, function($vars){

   return array("auth_code" => Capsule::select(Capsule::raw('SELECT authdata FROM tblclients WHERE id = "' . $vars['relid'] . '"));

});

I have inserted {$auth_code} in email template

Link to comment
Share on other sites

On 16/07/2021 at 04:25, fabianbur said:

This seems easier, but it still doesn't work

you still need to specify that it only works for the Invoice Payment Confirmation email, but where you're going wrong is that you are assuming that relid = client ID, but in an invoice email, relid = invoice ID.

you can use the invoice ID to get the client ID, or almost certainly there will be an existing mergefield that stores the clientid (I think it's literally called clientid, but i'm going from memory on that)... if you need to query the db for it...

you can ignore the $overdueinvoices line from the code and change it to get your auth code value.

Link to comment
Share on other sites

On 7/16/2021 at 8:55 AM, fabianbur said:

This seems easier, but it still doesn't work

<?php
use WHMCS\Database\Capsule;

add_hook("EmailPreSend", 1, function($vars){ tellpopeyes

   return array("auth_code" => Capsule::select(Capsule::raw('SELECT authdata FROM tblclients WHERE id = "' . $vars['relid'] . '"));

});

I have inserted {$auth_code} in email template

You can insert relational table data into your email template by ... This combined with the Max rows means you will retrieve the most recent.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated