Created
August 12, 2015 10:01
-
-
Save woogist/9919fe9649163906c021 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() { | |
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