Can only purchase a product after X days

Discussion in 'Customization & add-ons' started by brunopt, Nov 1, 2017.

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

    brunopt aMember Pro Customer

    Joined:
    Mar 19, 2012
    Messages:
    7
    Hey guys,

    Is it possible to have an option for the customer to only purchase a chosen product after the user has been subscribed for at least 30/60/90 days to another product?

    Let's say I have an entry level X product, and I want the user to go through it for at least 30 days before buying the sequel Y product. Can I do this in amember? I couldn't find any option for it on the backend.

    Thank you.
  2. caesar

    caesar aMember Pro Developer Staff Member

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

    I am afraid it is not possible to do by default but aMember is flexible enough and allow quite quickly
    extends its functionality in any expect in upgrade proof way. In case of your task you can use the following code in
    site.php to add such new feature:
    http://www.amember.com/docs/Site.php_file

    PHP:
    //add new fields to product settings page
    //aMember CP -> Products -> Manage Products -> (edit)
    Am_Di::getInstance()->productTable->customFields()->add(
        new 
    Am_CustomFieldText('c_days''Days',
            
    'require user to have active subscription to below product at least configured number of days in order to pucrhase current product'));
    Am_Di::getInstance()->productTable->customFields()->add(
        new 
    Am_CustomFieldSelect('c_pid''Required Product'''null, array(
            
    'options' => array(''=>'') + Am_Di::getInstance()->productTable->getOptions()
        )));

    //remove product from signup form if
    //user does not meet configured requirements
    Am_Di::getInstance()->hook->add(Am_Event::SIGNUP_FORM_GET_PRODUCTS, function(Am_Event $e) {
        
    $ret $e->getReturn();
        
    $user $e->getDi()->auth->getUser();
        foreach (
    $ret as $k => $product) {
            if ((
    $d $product->data()->get('c_days')) &&
                (
    $pid $product->data()->get('c_pid'))) {

                if (!
    $user || $e->getDi()->db->selectCell("SELECT days FROM ?_access_cache WHERE fn=? AND id=? AND user_id=?"'product_id'$pid$user->pk()) < $d) {
                   
                    unset(
    $ret[$k]);
                }
               
            }
        }
        
    $e->setReturn($ret);
    });
  3. brunopt

    brunopt aMember Pro Customer

    Joined:
    Mar 19, 2012
    Messages:
    7
    Great! Thank you!
  4. 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