WooCommerce 会员资格有一些条件,但我不能将它们结合起来专门测试特定成员是否可以访问特定内容。
$post_id = get_the_ID(); // this post is available to access level 'insights' but *not* available to a member with access level 'resources'
// if post content is restricted
if ( wc_memberships_is_post_content_restricted($post_id) ) {
// returns true for *any* restricted content (whether restricted for this member or not)
// check if user has membership
$user_id = get_current_user_id(); // this member has access level 'resources' but not 'insights'
if ( wc_memberships_is_user_active_member( $user_id, 'resources' ) ){
/// will return *true* dependent on user but *not* dependent on content
echo "You";
} else {
echo 'Not you ';
}
}
总是返回“你”
那么如何检查此用户是否具有此内容的访问级别?
用简单的英语,我想我需要找出对帖子内容施加了哪些限制,但似乎没有条件(这很奇怪)