Forum

Thread tagged as: Question, Addons, Members

Members App: Make certain content on the page only visible to certain individua...

How can I make certain content on the page only visible to certain members? I do not mean member tags as this would be for individual members rather than groups of members.

I imagine first I would need to allow selection of allowed users from the back office. So for example, I have a page that lists a number of product ranges. I want to allow some ranges to be visible only to certain members, so on the range region, I would like to show a list of all members on the system (dynamically) and allow selection of multiple members (are check boxes or a select box best?).

Then on the page, I need to filter for that value and check it against the current user to show only ranges that have been assigned to them.

Is this at all possible? If so, how would I go about it?

Lisa Morena

Lisa Morena 1 points

  • 5 years ago

Hi,

This might be of help to you - check against the email rather than a tag:

https://forum.grabaperch.com/forum/06-24-2015-client-area-using-tags-or-members-email-address-any-suggestions

Yes, thanks - I did come across that, however I need to be able to apply the content to multiple users, but not all.

I really need some way of selecting which members (from a dynamicly created list of all members) that a particular region can be viewed by.

If only it was a simple as limiting it to just the one user!

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's how the tags are designed to work - they can be applied to one or more users.

OK, so is there a central place to create tags and then just tick all that are relevant on the member account page? Not sure I get how they work exactly.

So I would create a tag for the product range and then apply that tag to the user? So each user can have more than one tag too.

Is that any easier to do using the Shop App (as per out other discussion!)?

OK, so thinking aloud, if I use the Shop App, I suppose what I want is to be restricting shop categories to certain members. I could create tags for members with identical names to the categories, but that leaves us open to errors since there could be a misspelling or a category name could be changed and the tag not updated.

I either need to be able to create the tag on the category set up page and then select it on the back office profile page for the member or set up the tag somewhere central and select it from available tags for both the category and the member.

Then how would I go about showing all categories that match the tag(s) of the current logged in member? It needs to be dynamic as it is not something I can hard code.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think you'll be able to do it with categories, but you should be able to add tags to products.

Categories themselves can't be filtered.

OK, but I would have to manually add the tags to the products and then to the member? I cannot create the tag in one place and then select from a list of available tags elsewhere? I am just trying to avoid mistakes with regards to spelling, etc.

If you can just point me in the right direction here as I am new to both the Shop App and the Members App. Product tags are only applied after purchase, so I cannot use those.

Right, I have been having a play and have been able to hide shop entire shop categories from certain members. In this instance, I do not need individual product pages, just a list of products and add to cart buttons on the category page, so I have used the category slugs as tags for the members.

I then used

if (perch_member_has_tag(perch_get('s')))

to only show the contents if a member has a tag that matches the category slug. It is not perfect since it is open to errors due to misspellings or renaming of the category, but it does work. I am open to better suggestions if these potential issues can be avoided.

The last thing I want to do is to hide any categories that the member is not allowed to see from the list of categories. For this page, I use:

   perch_categories(array(
       'set'=>'products',
       'category'=>'wholesale-products',
       'template'=>'category-list.html',
    ));

Category list looks like this:

<perch:before><ul></perch:before> <perch:if id="catParentID" match="gt" value="0">
<li style="margin-left: <perch:category id="catDepth" type="hidden" />0px;">
    <a href='category.php?s=<perch:category id="catSlug" type="slug" for="catTitle" />'>
    <h4><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></h4>
    <perch:category id="catSlug" type="slug" for="catTitle" suppress="true" />
    <perch:category id="desc" type="textarea" label="Description" editor="markitup" markdown="true" size="s" />
    </a>
</li></perch:if>
<perch:after></ul></perch:after>

How can I go about only showing categories whose slug matches the member's tag?

Aha! Got ot working with this:

if (perch_member_logged_in()) {
if (perch_member_has_tag('wholesale-products')) {



    $SubCategories = perch_categories([
                    'skip-template' => true,
                    'filter'=> 'catParentID',                    
                    'match'=> 'eq',
                    'value'=> 2 // Category ID of wholesale-products
                ]);
     ?>
     <ul>
     <?php foreach ($SubCategories as $SubCategory) { 
        if (perch_member_has_tag($SubCategory['catSlug'])) {
     echo '<li><a href="?s='.$SubCategory['catSlug'].'">'.$SubCategory['catTitle'].'</a></li>';
      }   
     }//end for each  ?>
     </ul>
     <?php


}
}