Created
August 5, 2015 09:24
-
-
Save woogist/0893c2d668dfe8497176 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'wp', 'custom_hidden_comments' ); | |
function custom_hidden_comments() { | |
$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; | |
$restricted = ( in_array( $post->post_type, array( 'product', 'product_variation' ) ) ) | |
? wc_memberships_is_product_viewing_restricted() && ! current_user_can( 'wc_memberships_view_restricted_product', $post->ID ) | |
: wc_memberships_is_post_content_restricted() && ! current_user_can( 'wc_memberships_view_restricted_post_content', $post->ID ); | |
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