PDF Invoice | Add custom field to invoice

Discussion in 'Customization & add-ons' started by info_idonline_co_za, Aug 1, 2017.

Thread Status:
Not open for further replies.
  1. info_idonline_co_za

    info_idonline_co_za aMember Pro Customer

    Joined:
    Aug 16, 2012
    Messages:
    8
    Hi Alex,

    I want to add custom fields I defined in the add user fields section to the invoice, I am not sure how to call these fields so it displays on the invoice I know I must edit this section to keep the customisations intact after upgrades, can you point me in the right direction?

    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::PDF_INVOICE_COL_LEFT, function (Am_Event $event) {
        
    /* @var $payment InvoicePayment */
        
    $payment $event->getPayment();
        
    $col $event->getCol();
        
    //print_rre($col); //you can uncomment this line and see what is present in $col object
        
    $col->add('Invoice Number: ' $payment->pk(), 'invoiceNumber'); // alter some line
        
    $col->remove('date'); //remove line
        
    $col->add('Some additional text'); //add line
    });
    The fields currently are:

    upload_2017-8-1_8-51-33.png

    I want to add any custom field or system field defined in the sign up forms when a user signs up

    Regards,
    Al
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hello,

    What is name and type (SQL or DATA) of these two fields?

    You can check it at
    aMember CP -> Configuration -> Add User Fields

    additional-fields.png
  3. info_idonline_co_za

    info_idonline_co_za aMember Pro Customer

    Joined:
    Aug 16, 2012
    Messages:
    8
    Hi,

    it is all [data] and is institution_name and institution_vat_number

    thanks,
    Al
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You can use the following code in site.php:
    http://www.amember.com/docs/Site.php_file

    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::PDF_INVOICE_COL_LEFT, function (Am_Event $e) {
        
    $payment $e->getPayment();
        
    $user $payment->getUser();
        
    $col $e->getCol();
       
        
    $col->prepend("VAT nr: {$user->data()->get('institution_vat_number')}");
    });

    Am_Di::getInstance()->hook->add(Am_Event::PDF_INVOICE_COL_RIGHT, function (Am_Event $e) {
        
    $payment $e->getPayment();
        
    $user $payment->getUser();
        
    $col $e->getCol();
       
        
    $col->prepend($user->data()->get('institution_name'));
    });
    info_idonline_co_za likes this.
  5. info_idonline_co_za

    info_idonline_co_za aMember Pro Customer

    Joined:
    Aug 16, 2012
    Messages:
    8
    Hi Ceasr,

    Thanks it works well.
    PHP:
    {$user->data()->get('institution_vat_number')}
    this was what I was getting wrong.

    Al
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You are welcome!
Thread Status:
Not open for further replies.

Share This Page