PHP Code to Display Depending on Product

Discussion in 'Setting-up protection' started by ak48avk, Mar 26, 2018.

  1. ak48avk

    ak48avk Angela Kane

    Joined:
    Aug 9, 2010
    Messages:
    124
    Hello,

    I use this simple code to display a message depending on isLoggedIn -

    <?php if(Am_Lite::getInstance()->isLoggedIn()) : ?>
    Free Sewing Pattern Downloads
    <?php else : ?>
    Join for All Sewing Pattern Downloads
    <?php endif;?>

    I would now like to take advantage of haveSubscription.

    <?php if(Am_Lite::getInstance()->haveSubscriptions(array(3,25,89,105))) : ?>

    FULL SUB or ONE YEAR SUB or NEW DEAL or NEW DEAL ONE YEAR

    <?php endif; ?>

    But I want it to mean product 3 or 25 or 89 or 105. It seems to mean 3 and 25 etc.

    I tried using a category number which groups all these products but that is not working either.

    Help would be much appreciated as always.
  2. ak48avk

    ak48avk Angela Kane

    Joined:
    Aug 9, 2010
    Messages:
    124
    I think I have the answer now:

    <?php if(Am_Lite::getInstance()->haveSubscriptions(array(3) or (89) or (25) or (105)) )

    : ?>

    FULL SUB, ONE YEAR SUB, NEW DEAL, NEW DEAL ONE YEAR

    <?php endif; ?>


    It seems to work. Is this the way?
  3. ak48avk

    ak48avk Angela Kane

    Joined:
    Aug 9, 2010
    Messages:
    124
    Trial and error, sorry that's not working.
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Please try this one:

    PHP:
    <?php if (Am_Lite::getInstance()->haveSubscriptions(array(38925105))): ?>
    FULL SUB, ONE YEAR SUB, NEW DEAL, NEW DEAL ONE YEAR
    <?php endif; ?>
  5. ak48avk

    ak48avk Angela Kane

    Joined:
    Aug 9, 2010
    Messages:
    124
    Hello Caesar,

    Thank you so much. That works. So is that just because of the spacing?
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    No, spacing does not matter. Method haveSubscriptions accept array of product ids.

    Here is difference between your code and mine:
    Code:
    array(3) or (89) or (25) or (105)
    and
    Code:
    array(3, 89, 25, 105)
  7. ak48avk

    ak48avk Angela Kane

    Joined:
    Aug 9, 2010
    Messages:
    124
    Thanks so much. I may have wasted your time as that is what I tried first but without spacing. See my first post. I must have done something that made it fail first time.

    But it's working as it should now. A great little bit of code and I should make much more use of these features.

    Thanks again.
    Angela
  8. ak48avk

    ak48avk Angela Kane

    Joined:
    Aug 9, 2010
    Messages:
    124
    While I am about it, how do I show a User name. I gather I use the following but how do I code it to appear.
    <?php Am_Lite::getInstance()->getUsername() ?>

    I know I have bored this Forum before! I'm a coder (programmer) active late 60's through 1980. Assembler, Cobal etc. Our tools - coding pad, pencil, rubber and a good memory. It's a different world when there is access to so much information. PHP syntax is a complete mystery to me! But thankfully we have this splendid team at aMember who always responds so quickly and efficiently.

    I still like control and template websites have no appeal. Although I use a tiny fraction of aMember's features, it's a joy to use. I can do what ever I want. It is an amazing tool backed up by great support.

    So to save me learning PHP code and syntax, it's great to have the aMember team on hand, filling in the knowledge for me.
  9. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Please try this code:
    PHP:
    <?= htmlspecialchars(Am_Lite::getInstance()->getUsername()); ?>
    It should do the job.

    Best Regards.
    relapse likes this.
  10. ak48avk

    ak48avk Angela Kane

    Joined:
    Aug 9, 2010
    Messages:
    124
    Thank you very much. This has been very helpful.
    caesar likes this.

Share This Page