Updating a members record with a value from a products record

Discussion in 'Customization & add-ons' started by todddown, Dec 30, 2009.

  1. todddown

    todddown Member

    Nov 24, 2009

    I have a subscription which buys a certain amount of time(e.g product #1 gets 720 minutes). When the subscription is bought I want the amount of time that it's worth to be added to the users record as time remaining so I use the following hook in site.inc.php:

    add_member_field('time_remaining', 'Time Remaining', 'text', '');
    add_product_field('time_remaining', 'Time Remaining', 'text', '');

    function ums($payment_id){
    global $db;
    $p = $db->get_payment($payment_id);
    $c = 0;
    foreach ($db->get_user_payments($p['member_id'], 1) as $p){
    $pr = $db->get_product($p['product_id']);
    $c += $pr['time_remaining'];
    $u = $db->get_user($p['member_id']);
    $u['data']['time_remaining'] = $c;
    $db->update_user($u['member_id'], $u);

    setup_plugin_hook('finish_waiting_payment', 'ums');


    It works ok, and when #1 is bought it adds the time value of it to the users record. However when the same user then buys another different subscription the original time value of #1 is applied again. This appears to happen with every product bought until the users original subscription to #1 is expired or deleted. Does anyone know a way that I can get the time_remaining value of a subscription added to a users record once only whilst that subscription is valid and stop it being added again whenever another subscription is added?

Share This Page