How to post expiration date for member?

Discussion in 'Templates customization' started by jcary, Jan 18, 2011.

  1. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Tried searching but couldn't find answer...

    How do I list a member's expiration date inside their members area?

    I understand an issue might be choosing which subscription to show if there is more than one, but surely there's a way:

    "Hi <?php echo ($_SESSION[_amember_user][name_f]);?> Your current subscription ends on [CODE NEEDED HERE!]"

    Thanks.
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    This should work:
    PHP:
    <?php
    foreach($_SESSION[_amember_subscriptions] as $p){
        if(
    $expire_date <$p['expire_date']) $expire_date $p['expire_date'];
    }
    print 
    $expire_date;
    ?>
  3. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    That looks close, Alex,

    But that code seems to output:

    2037-12-31

    for each user...

    Do I need to define a specific subscription or something?

    Thanks again.

    -Josh
  4. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    I only have one product and use
    Code:
    {$payments[0].expire_date|amember_date_format:"%B %e %G"}
    and that produces date in the format 'August 25 2012'
  5. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Sorry for my lack of php knowledge, but where exactly does your code:

    {$payments[0].expire_date|amember_date_format:"%B %e %G"}

    fit into the entire block of code?

    Thanks.

    -Josh
  6. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    As said I only have one and the full entry, relating to the date, on the template file is:
    Code:
    <span class="amem_profile_1">Account expiry date:</span>
                            <br />
                             <span class="amem_profile_2">{$payments[0].expire_date|amember_date_format:"%B %e %G"}</span>
    This was supplied by aMember some time ago and produces on the web page:
  7. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    jcary,
    What payment systems you use? Do you have lifetime products?
  8. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Hi Alex,

    I am using Paypal... and I do have some subscriptions set as Lifetime, BUT the one subscription I'm trying to get the expiration date for is an annual subscription (renews every year).

    Thanks.

    -Josh
  9. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    If you have old aMember version with old plugin, aMember can set subscription expire date to lifetime for recurring subscriptions. This was changed in recent versions so expiration date is correct for recurring subscriptions. I guess you need to upgrade.
  10. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Hi Alex,

    I'm currently using aMember version 3.2.3PRO. But what plugin are you referring to? What do I need to update?
  11. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    You said you tested my code and it output 2037-12-31 for each user, can you also attach screenshot of payment history of that user.(You can do this in helpdesk if you don't want to put it here)
  12. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Hey Alex,

    Here is screenshot of Payment History example...
  13. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    So displayed date were correct.
    That user have two lifetime subscriptions so expiration date was 2037-12-31 (Lifetime)
  14. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Oh. IS there a way to specify which product/subscription expire date to show?

    For example, I want to show member the expire date for their Basic Membership, which renews once a year.
  15. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    The screen shot shows the member having seperate products. So which date do you want to display?

    One for each product or when their final subscription ends, in which case Alexanders answer is correct.
  16. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    For exact product you can use:
    PHP:
    <?php
    foreach($_SESSION[_amember_subscriptions] as $p){
        if((
    $p[product_id] == 1) && ($expire_date <$p['expire_date'])) $expire_date $p['expire_date'];
    }
    print 
    $expire_date;
    ?> 
    This will display latest expiration date for product 1
  17. gusfune

    gusfune New Member

    Joined:
    Feb 20, 2011
    Messages:
    11
    Is it possible to modify this snippet to use a different date-format than YYYY-MM-DD?

    I'd like to output a custom format, like only the month, or the day. Or even going further, being able to make a counter that says: "there are x days remaining in your subscription".

    How can this be achieved?
  18. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Here is an example:
    PHP:
    $expire_date round((strtotime($expire_date) - time()) / (24*3600)); 
    print 
    $expire_date
    This will output days from now to expiration date.
  19. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Alex,

    Your code is excellent. Thanks so much for providing that.

    I do have a specific question, or two...

    1) How can we display the date in a different format than "2012-06-24" - ideally, I'd want to see format "June 24, 2012"

    2) If my desired output for my members is for them to see this:

    Your membership is set to expire on June 24, 2012 which is in 560 days.

    Is this format the most logical way to achieve that (this code does currently work, but not sure if it's the best way)...

    PHP:
    <?php
    foreach($_SESSION[_amember_subscriptions] as $p){
        if((
    $p[product_id] == 3) && ($expire_date <$p['expire_date'])) $expire_date $p['expire_date'];
    }
    print 
    "Your membership is set to expire on $expire_date "
    ?>

    <?php
    foreach($_SESSION[_amember_subscriptions] as $p){
        if((
    $p[product_id] == 3) && ($expire_date <$p['expire_date'])) $expire_date $p['expire_date'];
    }
    $expire_date round((strtotime($expire_date) - time()) / (24*3600));
    print 
    "which is in $expire_date days."
    ?>
    3) Finally, if I have 3 different product levels (product 1, 2 and 3), is there a logical way to code this to say something like

    PHP:
    $p[product_id] == || $p[product_id] == || $p[product_id] == 3
    I tried that and it didn't seem to work out.

    Thanks!

    -Josh
  20. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Josh,
    Here is modified code that have all three modifications:
    PHP:
    foreach($_SESSION[_amember_subscriptions] as $p){
        if((
    in_array($p[product_id], array(1,2,3))) && ($expire_date <$p['expire_date'])) $expire_date $p['expire_date'];

    print 
    "Your membership is set to expire on ".date("%F %d, %Y"strtotime($expire_date))." which is ".round((strtotime($expire_date) - time()) / (24*3600))." days"

Share This Page