Navigation überspringen

[Gelöst] Hiding some categories for visitors

This support ticket is created vor 1 Monat, 3 Wochen. 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 0 Antworten, hat 1 Stimme.

Zuletzt aktualisiert von Dido vor 1 Monat, 3 Wochen.

Assistiert von: Minesh.

Author
Artikel
#2787600

Hi,

on my site versteckter Link I have 4 products.
Only 1 product is for everyone, the rest are only availlable for members.

I have assigned the products to a member group, and that works. However, in the shop page they are not hidden.
How can I do this?

#2787784

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share admin access details as well as member access details and do you mean that on shop page those product should not be displayed?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2787874

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Can you please check now: versteckter Link

I've added the following code to "Custom Code" section offered by Toolset with the code snippet namely "toolset-custom-code":
=> versteckter Link

add_action( 'pre_get_posts', 'func_remove_products_from_access_group_posts_archive_result',99,1);
function func_remove_products_from_access_group_posts_archive_result( $query ) {
    // skip if admin side or not main query
    if ( is_admin() || ! $query->is_main_query() ) return;
 
    // check if the query is for a specific post type
    if ( in_array ( $query->get('post_type'), array('product') ) ) {
        $user = wp_get_current_user();
		
   global $wpcf_access;
   global $current_user;
   
     //// get the post group slug belongs to toolset access assigned to post to check the permission
    $post_group_slug = 'wpcf-custom-group-edffc382fce896fb1838d71d60d9ed58';
	$permited_roles = $wpcf_access->settings->types[$post_group_slug]['permissions']['read']['roles'];
	
	// get current user role
    $current_user_role = $current_user->roles; 
  
   
  $private_ids = array();
  if(empty($current_user_role)){ 
       
   $args = array(
        'post_type' => 'product',
        'meta_query' => array(
            array(
                'key' => '_wpcf_access_group',
                'value'    => $post_group_slug,
                ),
            ),
        'fields'    => 'ids',
        'posts_per_page' => -1,
    );
	
	///// get posts where post group is assigned 
    $private_ids = get_posts($args);
	
	/// remove the posts from the view result belongs to post group
	$query->set('post__not_in',$private_ids);
      
  }
           
  }
}

I can see now only one product that is publically available and not assigned to access post group.

#2787875

Very well, thank you!