Custom fields that tie to individual subscription, not user profile

Discussion in 'Customization & add-ons' started by hoangvn1509, Dec 8, 2015.

  1. hoangvn1509

    hoangvn1509 New Member

    Joined:
    Nov 8, 2015
    Messages:
    2
    Hi,
    I use Amember to sell a subscription to existing users multiple times.
    Each time the user buys, I need him to be able to enter a different domain name for his subscription (like selling hosting subscriptions)
    That domain name will be stored in his invoices/access page.
    So if he cancels the subscription, I know which domain that subscription is for.

    Please suggest how I could accomplish this or any other alternative ways you guys use.

    Thank you
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    There is not easy ability to do it from admin interface right now but you still can implement it the following way:

    1. add new user field 'domain' (make it SQL)
    aMember CP -> Configuration -> Add User Fields
    and add this field to your payment form.
    aMember CP -> Configuration -> Forms Editor

    2. in site.php (http://www.amember.com/docs/Site.php_file) add the following code:
    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::INVOICE_BEFORE_PAYMENT_SIGNUP, function(Am_Event $e){
        
    /* @var $invoice Invoice */
        
    $invoice $e->getInvoice();
        
    /* @var $user User */
        
    $user $invoice->getUser();
        if (
    $user->domain) {
            
    $invoice->data()->set('domain'$user->domain)->update();
            
    $user->updateQuick('domain''');
        }
    });

    Am_Di::getInstance()->blocks->add(new Am_Block('admin/user/invoice/right'null'invoice-domain'null, function(Am_View $v){
        if (isset(
    $v->invoice) && ($d =  $v->invoice->data()->get('domain'))) {
            return 
    $v->escape($d);
        }
    }));

Share This Page