Hello,
Using WooCommerce memberships we have several different subscription packages available on the website.
One of those is a Member (Free) membership plan, which enables the user to access the site for a short period of time and browse/view a selection of free resources.
Before you login, you will notice that if you use the main search in the header of the site, you are able to browse all resources in the search results.
When a free user logs in and tries to do so, they are returned 0 results. (From the main search in the header).
However, if that free user then navigates to hidden link
and uses the search field there, they are able to see the search results (All though its important to not they cannot download anything).
What we want to achieve is free members allowed resources to be searchable in the main header search as they are in the resources page.
Its presumed that 'Search: Global' view needs to have a change made to it so that it allows this. 'Resources: Search' and ' Generic: Search (Logged out)' already appear to allow this.
Can you indicate how we can achieve this please, its rather urgent.
I have provided both a free user and admin access below.
Thanks
While comparing these two Views I can see that the main difference is how the wpv-post-body shortcode is restricted in the loop. Here's the logged-out View:
hidden link
<wpv-loop>
[wpv-post-body view_template="loop-item-in-generic-search-logged-out"]
</wpv-loop>
No conditionals or anything, the wpv-post-body is shown for each result.
Now compare that loop to the logged-in View, here:
hidden link
<wpv-loop>
[wpv-conditional if="( has_term('teachers-plan', 'access-permission', null) ne '1' )"]
[wcm_restrict plans="member-standard"]
[wpv-post-body view_template="Loop item in Search: Global (Results)"]
[/wcm_restrict]
[/wpv-conditional]
[wpv-conditional if="( has_term('teachers-plan', 'access-permission', null) eq '1' )"]
[wcm_restrict plans="member-teacher"]
[wpv-post-body view_template="Loop item in Search: Global (Results)"]
[/wcm_restrict]
[/wpv-conditional]
</wpv-loop>
You can see the logged-in View has wpv-conditionals that test whether or not each result has a specific taxonomy term from the access-permission taxonomy. If not, that result is not shown. Then inside that conditionals is another shortcode that seems to be part of the WC Membership system, applying another type of restriction based on the membership plan. I'm not sure how these 3rd-party shortcodes work exactly or the correct logic to determine who sees what, but my guess is that you need to modify this conditional structure to work with another membership plan. Try this, or correct my logic if I've misunderstood what you want to accomplish:
<wpv-loop>
[wpv-conditional if="( has_term('teachers-plan', 'access-permission', null) ne '1' )"]
[wcm_restrict plans="member-standard"]
[wpv-post-body view_template="Loop item in Search: Global (Results)"]
[/wcm_restrict]
[/wpv-conditional]
[wpv-conditional if="( has_term('teachers-plan', 'access-permission', null) eq '1' )"]
[wcm_restrict plans="member-teacher"]
[wpv-post-body view_template="Loop item in Search: Global (Results)"]
[/wcm_restrict]
[/wpv-conditional]
[wpv-conditional if="( has_term('teachers-plan', 'access-permission', null) eq '1' )"]
[wcm_restrict plans="member-free"]
[wpv-post-body view_template="Loop item in Search: Global (Results)"]
[/wcm_restrict]
[/wpv-conditional]
</wpv-loop>
Thanks,
Just before we jump down the above code hole, did you look at the code behind the search on
hidden link
?
That is working as expected, so I want to check its not a case of just making a change to the other search that follows this, or using the code in place on the above search on the main search icon seen in the page header.
Thks
Just before we jump down the above code hole, did you look at the code behind the search
I'm not going there yet, because it's counter-productive. I can see that the results count for Free Members is different from the number of results shown in the list. That means the loop is skipping results, even though the query filter is finding results. This happens when conditionals are present around the content in the loop and none of the conditionals are true. No results will be displayed in the list but the number of results in the pagination section will show a non-zero number, and that's exactly what we're seeing here.
So again, please add these five lines of code to the Loop of View 1760 after the last conditional and before the closing wpv-loop tag:
[wpv-conditional if="( has_term('teachers-plan', 'access-permission', null) eq '1' )"]
[wcm_restrict plans="member-free"]
[wpv-post-body view_template="Loop item in Search: Global (Results)"]
[/wcm_restrict]
[/wpv-conditional]
Then purge your caches and test again as a Free Member. If no results are shown, add debug="true" to the wpv-conditional shortcode like this:
[wpv-conditional if="( has_term('teachers-plan', 'access-permission', null) eq '1' )" debug="true"]
Copy the results from the front-end of the site and share in your next reply, then you can remove debug="true" from the conditional code.
Hi, ok followed those steps and still im not able to see results in the generic search. I've added the debug code as requested.
Hi, I has to remove the code you provided as an impact was it started to hide search results for paid members of the site. Can you come back to me with a way forward.
What are these conditionals trying to accomplish?
- Why are there conditionals testing the "teachers-plan" term in the access-permission taxonomy?
- Why are there wcm_restrict tags for different membership types?
- Why is the content in each conditional restricted section the same - i.e. the Loop Item in Search: Global (Results) - if these conditionals and restrictions are in place to serve some purpose?
[wpv-post-body view_template="Loop item in Search: Global (Results)"]
Sorry,
But can you try speaking in plain English? I clearly explained what the challenge was at the start of the ticket and what outcome was required. The comment above makes little sense, we are after a solution outcome for this - with the clear steps and actions required to achieve it... 1- Do this 2: Then Do this 3: Then this.
This then ensures we resolve the issue without negative impacts.
I'm unsure where or what the code above is being suggested for.
Regards
I clearly explained what the challenge was at the start of the ticket and what outcome was required.
If you don't understand why I need to know about the conditionals that are already in place, please find someone who does and reassign the ticket to that person. I cannot verify any solution is working correctly without this knowledge.
I do not know the answers to the questions you are asking. Can you explain in more detail?
My question is:
Why is the content in this View's Loop enclosed in wpv-conditional shortcodes and wc-member shortcodes?
https://www.earlyyearsstaffroom.com/wp-admin/admin.php?page=views-editor&view_id=1760
This is important for us to understand because the problem for which you created this ticket involves content being hidden from certain Users, incorrectly. The reason some content is hidden is that there are conditional shortcodes and wc-member shortcodes in place in the View, restricting some of the search results. Each of the conditional shortcodes and wc-member shortcodes here is directly related to how the each item in the loop is restricted or unrestricted from the current User, which determines whether or not the current User can see that search result.
Someone needs to carefully examine the conditions currently in place and tell us why they are there. If they are unnecessary, we should remove them. If they are necessary, I need to know why they are necessary to make changes that work within those conditions.
It looks like the current conditionals are based on two criteria:
1. Whether or not the current post in the loop has the teachers-plan term assigned to it.
2. The type of Membership Plan assigned to the current User.
Please explain why these conditional codes are in place so we do not break things unexpectedly.
I can only imagine that those restrictions were placed to stop certain users with access from seeing that particular content.
Unfortunately, I wasn't involved in building the original platform or logic, so can not offer much more insight.
I presume if the below was removed it would open up the results to a wider audience? What would be the correct block to do so?
------
<wpv-loop>
[wpv-conditional if="( has_term('teachers-plan', 'access-permission', null) ne '1' )"]
[wcm_restrict plans="member-standard"]
[wpv-post-body view_template="Loop item in Search: Global (Results)"]
[/wcm_restrict]
[/wpv-conditional]
[wpv-conditional if="( has_term('teachers-plan', 'access-permission', null) eq '1' )"]
[wcm_restrict plans="member-teacher"]
[wpv-post-body view_template="Loop item in Search: Global (Results)"]
[/wcm_restrict]
[/wpv-conditional]
</wpv-loop>
I presume if the below was removed it would open up the results to a wider audience? What would be the correct block to do so?
If you removed all the code in your last reply, no results would be shown to any Users. I assume you mean removing some of the conditional shortcodes and membership shortcodes? If you don't want to restrict any search results from any users, the code you shared in your last reply should be replaced with this code:
<wpv-loop>
[wpv-post-body view_template="Loop item in Search: Global (Results)"]
</wpv-loop>
Then if results are still restricted from some Users we know it's not because of the conditional shortcodes or membership shortcodes that were previously in place.
Thanks, well that works to certainly show all the results. I need to check with the client that this is functioning as they wish.
Thanks for the support.