Billing Email

Discussion in 'Templates customization' started by thm43608, Oct 31, 2017.

  1. thm43608

    thm43608 aMember Pro Customer

    Joined:
    Jun 25, 2013
    Messages:
    7
    We often have members that need the invoice to be emailed to someone else. Is it possible to define a "Billing Email" field and have the invoice automatically emailed to that address in the event it is not empty?
  2. caesar

    caesar aMember Pro Developer Staff Member

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

    I am afraid there is not such feature by default.

    It is possible to implement custom solution to achieve it.

    You can add additional user field for billing email at
    aMember CP -> Configuration -> Add User Field

    add-user-field.png

    Then use the following code in site.php file to add this address as CC to email with payment receipt
    http://www.amember.com/docs/Site.php_file

    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::MAIL_TEMPLATE_BEFORE_PARSE, function(Am_Event $e) {
       
        
    $t $e->getTemplate();
        
    $c $t->getConfig();
        if (
    $c['name'] == 'send_payment_mail' && $t['user']->billing_email) {
            
    $e->getMail()->addCc($t['user']->billing_email);
        }

    });
    You can billing email field to either signup or profile form in drag & drop forms editor at
    aMember CP -> Configurations -> Forms Editor

    Best Regards.
  3. thm43608

    thm43608 aMember Pro Customer

    Joined:
    Jun 25, 2013
    Messages:
    7
    I don't have my payment receipts setup through Configuration >> Setup/Configuration >> E-Mail. Does this code only work for that? Is it possible to add a checkbox to the E-mail Messages to CC the billing email address?
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Yes, it works only for 'E-Mail Payment Receipt to User' in current implementation.
    Do you use Payment Emails from?
    aMember CP -> Protect Content -> E-Mails

    In this case you just need to replace name of template in my code above from 'send_payment_mail' to 'payment'.

    Best Regards.
    thm43608 likes this.
  5. thm43608

    thm43608 aMember Pro Customer

    Joined:
    Jun 25, 2013
    Messages:
    7
    That works perfectly, thank you!
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    It is great. You are welcome!
  7. techmatters

    techmatters aMember Pro Customer

    Joined:
    Jun 20, 2007
    Messages:
    4
    This is very useful. If I wish to send to a billing_email for Pending Invoices, can I just substitute the template name shown here with what I see in my Pending invoice template ? This is shown as misc.pending-notification.notify_pending . Is this valid to insert in the code above?
  8. techmatters

    techmatters aMember Pro Customer

    Joined:
    Jun 20, 2007
    Messages:
    4
    To clarify what I meant. Would the code look like this?

    Code:
    $t = $e->getTemplate();
    $c = $t->getConfig();
    if ($c['name'] == 'send_payment_mail' && $t['user']->billing_email) {
        $e->getMail()->addCc($t['user']->billing_email);
    }
         if ($c['name'] == 'misc.pending-notification.notify_pending' && $t['user']->billing_email) {
        $e->getMail()->addCc($t['user']->billing_email);
    }
  9. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Yes, code looks correct.

Share This Page