Newbie - trying to understand hooks

Discussion in 'Customization & add-ons' started by aleon, Apr 12, 2005.

  1. aleon

    aleon Guest

    I have read the help on hooks but don't yet understand them. I am an intermediate php and mysql developer.

    Basically I want to customise the signup page so that as well as creating a new reocrd in the amember table for a new user it also does other things like add records to a different table.

    I am fine with writing the code to add records to my other tables etc, but I don't know how to fit it into the amember signup page.

    Any help gratefully received.
    Cheers
    Aleon
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Aleon,
    you need to write a hook like described here:
    http://www.cgi-central.net/scripts/amember/docs/html/hooks_paymentsupdate.htm
    put it into file amember/site.inc.php (create it!)

    This hook will be called not when user makes signup. It will be called when user COMPLETES payment and I believe it is what you really need to catch. When user just filled-in aMember signup page, it doesn't mean anything, he can leave away without payment.

    You can try this by marking user payment record in aMember CP as paid. Hook will be called in this case.
  3. avatava

    avatava aMember Pro Customer

    Joined:
    Jun 17, 2008
    Messages:
    3
  4. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
  5. avatava

    avatava aMember Pro Customer

    Joined:
    Jun 17, 2008
    Messages:
    3
    This section is missing from the referred URL

    Thanks, I already looked in the manual- the page appears missing. I found the information myself in an old copy of the CHM Windows manual.
    ###begin missing section###
    Hooks - payments update


    finish_waiting_payment($payment_id)
    This function called when payment(subscription) status changes to Paid ("Completed"). Then you can retreive info from database about payment and use it to execute some actions.

    Please note - if admin switches payment status Paid -> NotPaid -> Paid from control panel, this function can be executed twice for the same payment. Be careful.

    Example of this hook function:

    function fwp($payment_id){

    global $db;

    $payment = $db->get_payment($payment_id); // $payment is now array

    $product = $db->get_product($payment['product_id']);

    $member = $db->get_user($payment['member_id']);

    print "For this period: $payment[begin_date] - $payment[expire_date]<br>";

    print "$product[title] ordered by $member[name_f] $member[name_l]<br>";

    }




    update_payments($payment_id)
    This function called when payment $payment_id has been updated somehow - changed, marked as paid, added, deleted.

    You can use the same code as for finish_waiting_payment function.


    ###end###

    Hopefully this may be useful to others. Thanks for your reply.

Share This Page