This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: membership and content access

#29736
Ernest MarcinkoErnest Marcinko
Keymaster

Thank you very much, this was extremely helpful. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

add_filter( 'asp_query_args', 'asp_exclude_restricted_posts', 10, 1 );
function asp_exclude_restricted_posts( $args ) {
	if ( ! current_user_can( 'wc_memberships_access_all_restricted_content' ) ) {
		if ( wc_memberships()->get_restrictions_instance()->hiding_restricted_products() ) {

			$conditions = wc_memberships()->get_restrictions_instance()->get_user_content_access_conditions();

			if ( isset( $conditions['restricted']['posts']['product'] ) ) {
				$args['post_not_in'] = array_unique(array_merge($args['post_not_in'], $conditions['restricted']['posts']['product']));
			}
		}
	}
	
	return $args;
}

In theory, this should be it – I was not able to test this, so please be carefuly.