Skip to content

Instantly share code, notes, and snippets.

@woogist
Created August 12, 2015 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woogist/9919fe9649163906c021 to your computer and use it in GitHub Desktop.
Save woogist/9919fe9649163906c021 to your computer and use it in GitHub Desktop.
add_action( 'wp', 'custom_hidden_comments' );
function custom_hidden_comments() {
if ( ! is_admin() ) {
$restrictions = wc_memberships()->restrictions;
remove_filter( 'wp', array( $restrictions, 'hide_restricted_content_comments' ) );
}
}
add_filter( 'wp', 'custom_hide_restricted_content_comments' );
function custom_hide_restricted_content_comments( $content ) {
if ( is_singular() ) {
global $post, $wp_query;
if ( in_array( $post->post_type, array( 'product', 'product_variation' ) ) ) {
$restrincted = wc_memberships_is_product_viewing_restricted() && ! current_user_can( 'wc_memberships_view_restricted_product', $post->ID );
} else {
// Get current user ID
$user_id = get_current_user_id();
// Check if the user is member of the plan 'silver'
if ( wc_memberships_is_user_active_member( $user_id, 'silver' ) ) {
$restricted = false;
} else {
$restricted = true;
}
}
if ( $restricted ) {
$wp_query->comment_count = 0;
$wp_query->current_comment = 999999;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment