I am trying to:
hide some woocommerce products from guests, for that I use S2Member plugin, and that works perfect exept 1 situation.
Link to a page where the issue can be seen:
1. scenario when everything ok : go to the hidden link (products with sku 207830, 207825, 207810 are hidden and thats OK)).
2. go to the hidden link THEn go to the page #2 and you can see them on that page in first column (pagination is done AJAX, but with no checking for S2 capability - hide product from guests). I thing the case is to write some js check under the JS section of Filter chapter for WordPress Archive (please see screen 2)
I expected to see:
hidden sku 207830, 207825, 207810
Instead, I got: I can see them for scenario 2
I understand the issue, and you spot on correctly see what needs to be done.
Toolset Support cannot write this snippet, however, as it is not something supported by the policy:
https://toolset.com/toolset-support-policy/
You would need to know the precise JS Function that hides the items (S2Member plugin), then re-fire that in the Views Filters JS Front end Events.
Most likely, since you use pagination, you would have to fire this at the only available pagination event which is when the pagination is done:
jQuery( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) {
/**
* data.view_unique_id (string) The View unique ID hash
* data.effect (string) The View AJAX pagination effect
* data.speed (integer) The View AJAX pagination speed in miliseconds
* data.layout (object) The jQuery object for the View layout wrapper
*/
//Here fire the Plugins function again.
});
This is also possible on Archive Views meanwhile, in the Filter Section.
You could ask the author of that plugin what function is handling the access (hides content) and then refire that in the filter section.
Hi, think I found the right function - attach_s2member_query_filters() , but the question is - how to implement it in a right way
My filter section looks liike this as for now
jQuery( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) {
jQuery("html, body").animate( {scrollTop: 0}, "fast");
jQuery('a.add_to_cart_button, button.ajax_add_to_cart').prepend('<i class="fa fa-cart-plus" aria-hidden="true"></i>');
function($) {
function attach_s2member_query_filters() {
query_posts("posts_per_page=10");
if (have_posts()):
while (have_posts()):
the_post();
endwhile;
endif;
wp_reset_query();
};
function detach_s2member_query_filters();
};
});
S2Members plugin snipet
<?php
attach_s2member_query_filters();
query_posts("posts_per_page=5");
if (have_posts()):
while (have_posts()):
the_post();
# Protected content will be excluded automatically.
# (based on the current User's Role/Capabilities)
endwhile;
endif;
wp_reset_query();
detach_s2member_query_filters();
?>
but unfortunally I can't make it working
As outlined, I cannot help with the custom code within the hook we provide to re-fire the 3rd party code.
You have to ask that plugin's support what function it is, that controls the features you want to re-fire.
Sometimes those are several functions and sometimes you cannot re-fire them because they require other things from their code that you cannot fire several times like a function
Once you know what precise function is required you can simply add that in the hook of the Toolset, there should be no need to add the entire code of that function again.
Also the second plugin snippet you provide is PHP; that won't work in the JS code.