Skip Navigation

[Resolved] Custom capabilities vs AJAX issue for Toolset

This support ticket is created 5 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Author
Posts
#1194476
2019-02-01_19-21-34.png
2019-02-01_19-21-09.png
2019-02-01_19-17-57.png

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

#1194631

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.

#1213182

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();
?>
#1213183

but unfortunally I can't make it working

#1213675

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.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.