get user subscrption information

Discussion in 'Troubleshooting' started by chmava, Aug 28, 2013.

  1. chmava

    chmava New Member

    Joined:
    Aug 26, 2013
    Messages:
    3
    Hi,

    i have search the whole forum and internet and could not find this issue.

    the solution available here does not work:
    http://manual.amember.com/AMember_Session_Variables

    it do not return any value for subscription plan.

    is there another way? or do i have to use pure mysql php command to access this?
    cause the later seem like i'm hacking my own system.......................

    regards
  2. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
  3. chmava

    chmava New Member

    Joined:
    Aug 26, 2013
    Messages:
    3
    that was clearly a bad idea, as i am calling this from within amember system iteself and not from an external script.
  4. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Is it?? Hard to give any ideas good, or bad, with no real idea of what you are trying to achieve!!
  5. chmava

    chmava New Member

    Joined:
    Aug 26, 2013
    Messages:
    3
    hi,

    sorry, this function is confusing: Am_Lite::getInstance()->haveSubscriptions($search)
    for $search if i use array(1,3), do the script search from plan with id 1-3 or 1 and 3?
    like this: Am_Lite::getInstance()->haveSubscriptions(array(1,3))

    regards
  6. dale_s

    dale_s aMember Pro Customer

    Joined:
    Apr 12, 2013
    Messages:
    96
    Anyone ever figure this out? Any suggestions on the correct syntax (array, etc) when there is more than one subscription? I keep trying to figure it out but am stuck.
  7. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
  8. dale_s

    dale_s aMember Pro Customer

    Joined:
    Apr 12, 2013
    Messages:
    96
    I am using the same code as mentioned by chmava in this post, in a php page of my site:

    Code:
    Am_Lite::getInstance()->haveSubscriptions(array(1,3))


    With one subscription and without the array, the code works great. But with 2 or more, it breaks. I'm just wondering about the correct syntax would be when using 3 subscriptions. Thanks for any suggestions.
  9. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Can you post up all of the code?

    I wanted to check arrays for two possible products when adding a tab, in site.php script, and split them to into two
    PHP:
    if (in_array ($user->getActiveProductIds()) OR in_array ($user->getActiveProductIds())) 
    so wondering if you could split yours if you were using an 'if' statement for instance
    PHP:
    if (Am_Lite::getInstance()->haveSubscriptions(1) OR Am_Lite::getInstance()->haveSubscriptions(1) )
  10. robw

    robw CGI-Central Partner

    Joined:
    Dec 18, 2007
    Messages:
    287
    I realise this thread is probably too old now, but just in case it's useful to someone in the future...

    If checking from within aMember (i.e. plugin or site.php) you can use something like this:

    PHP:
    $activeProductIds Am_Di::getInstance()->user->getActiveProductIds();
    if (
    in_array('3'$activeProductIds)) {
        
    // Has subscription to product 3, so do something...
    }

    if (
    array_intersect(array(1,6), $activeProductIds)) {
        
    // Has subscription to either product 1 or 6, so do something...
    }
       
    If checking from within WordPress, you can query via the aMember plugin. Here's a function I wrote that you can put into your functions.php that lets you query subscriptions. (The advantage of using a function in your theme is that you have a single point of change if the plugin changes, plus you don't kill your theme if you delete the aMember plugin :)

    PHP:
    /***
    * Check if user has active amember subscriptions
    *
    * @param  int|array $search
    * @return bool
    */
    function am4_has_amember_subscriptions($search='any')
    {
        if (!
    class_exists(am4PluginsManager)) return false;
        return 
    am4PluginsManager::getAPI()->haveSubscriptions($search);
    }
    To call the above function in one of your theme pages, use something like:

    PHP:
    if ( am4_has_amember_subscriptions( array(3,1,5,7,12) ) )  {
        
    // Has one or more of subscriptions 3, 1, 5, 7 or 12, so do something...
    }
    If calling from some other PHP script, you can use AM_Lite using something like:

    PHP:
    // Check login
    $search = array(12,4,9,10,13,5);
    require_once 
    '/home/path/to/amember/library/Am/Lite.php';
    if ( 
    Am_Lite::getInstance()->haveSubscriptions($search)  ) {
        
    // Do something
    }
    Cheers
    Rob
    Last edited: Apr 29, 2015
    Lynette likes this.
  11. dale_s

    dale_s aMember Pro Customer

    Joined:
    Apr 12, 2013
    Messages:
    96
    @robw - I just stumbled across this again. Your WordPress suggestion seems like a great option. Unfortunately, the 3rd code block you pasted seems to be throwing errors for me. My editors are saying there is a syntax error of some kind (extra parenthesis). I've been trying to play with it, but no luck? Of course, I'm no coder by any means. Is there is an error in what you posted, do you have an idea for a fix? Thanks for any clarification.
  12. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    There is no problems with code in that block. Can you attach full source code and exact error message?
  13. dale_s

    dale_s aMember Pro Customer

    Joined:
    Apr 12, 2013
    Messages:
    96
    @alexander - Thanks for the reply. I'm sure it's probably some error on my part, but I am trying to use this in one of my WordPress theme files:

    Code:
    <?php
    if ( am4_has_amember_subscriptions( array(3,1,5,7,12) )  {
    // Has one or more of subscriptions 3, 1, 5, 7 or 12, so do something...
    }
    ?>
    I keep getting message from editor say there is something wrong with the " {" in line 2. So if I was to put this in a theme file, what should it look like? Thanks for any help.
  14. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Try this:
    PHP:
    <?php
    if ( am4_has_amember_subscriptions( array(3,1,5,7,12) ) )  {
    // Has one or more of subscriptions 3, 1, 5, 7 or 12, so do something...
    }
    ?>
    There is one missing ) in your code
  15. dale_s

    dale_s aMember Pro Customer

    Joined:
    Apr 12, 2013
    Messages:
    96
    I need to sharpen up - I should have seen that missing )

    Anyways, seems to work now. I have this and just wanted to make sure it's a correct way to use code:

    PHP:
    <?php
    if ( am4_has_amember_subscriptions( array(3,21) ) )  {
    {
    }                 
    ?>
    <p>some text that will show here for 3 and 21</p>
    <?php
    }
    ?>
    Thanks for any clarification.
  16. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    No that code is incorrect.
    Here is how it should be:
    PHP:
    <?php if ( am4_has_amember_subscriptions( array(3,21) ) )  :  ?>
    <p>some text that will show here for 3 and 21</p>
    <?php endif; ?>
  17. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Alexander should the ':' in line 1 [( am4_has_amember_subscriptions( array(3,21) ) ) : ?>] not be a ';'?
  18. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
  19. dale_s

    dale_s aMember Pro Customer

    Joined:
    Apr 12, 2013
    Messages:
    96
    Works great - thanks for the clarification.
  20. robw

    robw CGI-Central Partner

    Joined:
    Dec 18, 2007
    Messages:
    287
    Hi Dale,

    Just to pick up on the alternative syntax comment - Alexander was saying that there was an error in your code as posted. You can use regular parenthesis notation too, its just that what you had posted had an error.

    Here it is with correct syntax:

    PHP:
    <?php
    if ( am4_has_amember_subscriptions( array(3,21) ) )  {
    ?>
    <p>some text that will show here for 3 and 21</p>
    <?php
    }
    ?>
    Cheers
    Rob

Share This Page