Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › membership and content access › Reply To: membership and content access
October 12, 2020 at 8:45 am
#29736
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.