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
    Alex,

    That is so perfect. Thanks!

    The only adjustment I had to make was removing the % from the %F %d, %Y part. (The output was %January %20, %2012)

    Thanks for that.

    -Josh
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Yes of course, that was my mistake )
  3. gungeuk

    gungeuk New Member

    Joined:
    Aug 13, 2010
    Messages:
    9
    With this code, I presume I put it into member.php, how do I call the command on member_main.html template?
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    In order to use above php code in smarty template, place it inside {php}{/php} tags
  5. gungeuk

    gungeuk New Member

    Joined:
    Aug 13, 2010
    Messages:
    9
    I presume as I am having issues with the header.php as in my other post, that is why this isn't working? Unless you can post the code I would use to display this in member.html template?

    Many Thanks
  6. asfarley

    asfarley New Member

    Joined:
    Jan 14, 2011
    Messages:
    1
    Heres How I Did It

    This will post the expiration dates right next to the active product links, just style class="amemberExpire" span to make it look good.

    This code only uses smarty syntax no need for {php} tags.

    The important code is:

    {foreach from=$smarty.session._amember_subscriptions item=g}
    {if $p.product_id == $g.product_id}
    <span class="amemberExpire">Expires {$g.expire_date|date_format:"%m/%d/%Y"}</span>
    {/if}
    {/foreach}

    you can place this anywhere within the {foreach from=$member_products item=p} {/foreach} tags in member_main.html. I add it right after the product title link.

    HERES MY COMPLETE member_main.html:

    <!-- display links to protected areas for customer -->
    <div id="amemberActiveProducts">
    {if $smarty.session._amember_products}{* Customer have active subscriptions, display it if config allows *}
    <h3>Active Products</h3>
    <ul>
    {foreach from=$member_products item=p}
    <li>
    {if $p.url gt "" }
    <a href="{$p.url}">{$p.title}</a>
    {foreach from=$smarty.session._amember_subscriptions item=g}
    {if $p.product_id == $g.product_id}
    <span class="amemberExpire">Expires {$g.expire_date|date_format:"%m/%d/%Y"}</span>
    {/if}
    {/foreach}

    {else}
    <b>{$p.title}</b>
    {/if}
    </li>
    {foreach from=$p.add_urls item=t key=url}
    <li><a href="{$url}">{$t}</a></li>
    {/foreach}
    {/foreach}
    </ul>

    {else}{* Customer doesn't have any active subscriptions *}
    <h3>#_TPL_MEMBER_NO_SUBSCR#</h3>
    #_TPL_MEMBER_USE|<i>|</i>#<br />
    #_TPL_MEMBER_ORDER_SUBSCR#<br />
    {/if}
    <ul>
    {foreach from=$left_member_links item=t key=u}
    <li> <a href="{$u|escape}">{$t}</a></li>
    {/foreach}
    </ul>
    <!-- end of display links to protected areas for customer -->


    </div>
    <div id="amemberUseful">
    <h3>#_TPL_MEMBER_USEFUL_LINKS#</h3>
    <ul>
    <li><a href="{$config.root_url}/logout.php">#_TPL_MEMBER_LOGOUT#</a></li>
    <li><a href="{$config.root_url}/profile.php">#_TPL_MEMBER_CH_PSWD#</a></li>
    {foreach from=$member_links item=t key=u}
    <li><a href="{$u|escape}">{$t}</a></li>
    {/foreach}
    </ul>
    </div>
    <div style="clear:both"></div>
  7. rsigcourses

    rsigcourses Member

    Joined:
    Mar 8, 2011
    Messages:
    46
    I'm using
    Code:
    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";  
    But for some reason its always returning

    Code:
    Your membership is set to expire on January 01, 1970 which is -15224 days
    
  8. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Replace $p['expire_date'] to $p['expire_dat']
  9. rsigcourses

    rsigcourses Member

    Joined:
    Mar 8, 2011
    Messages:
    46
    So it'd be like this

    Code:
    foreach($_SESSION[_amember_subscriptions] as $p){
        if((in_array($p[product_id], array(1,2,3))) && ($expire_date <$p['expire_dat'])) $expire_date = $p['expire_dat'];
    } 
    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";
    
    But that still gave the same result.
  10. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    echo out the various values and see where the date / values are not right.
  11. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Where you try to use this code?
    Did you have session_start() line at the top of your php file?
    Here is correct code that will work:
    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";
    Also, above will count only products 1 2 or 3.
    So if you have different product IDs you should update this part: array(1,2,3)
  12. kcarey

    kcarey Member

    Joined:
    Dec 27, 2009
    Messages:
    42
    Alex,

    I implemented the above code. However, it is announcing expiration for the current active payment... it does not take into account the already paid "future" payments. How do I get this code to acknowledge that future payments have already been made and extend the expire message to show this true expiration date.

    Thanks!

    kcarey
  13. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    This info can't be extracted from session, but you can include aMember config and use aMember's API:
    PHP:
    include "/full/path/to/amember/config.inc.php";
    foreach(
    $db->get_user_payments($_SESSION[_amember_id],1) 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