【问题标题】:WooCommerce Memberships: Conditional Restricted Content CheckWooCommerce 会员资格:有条件的受限内容检查
【发布时间】:2016-10-08 03:06:45
【问题描述】:

我正在尝试制作一个页面链接菜单,人们在购买会员资格后可以访问(通过WooCommerce Memberships)。如果这些页面还没有访问权限,我希望这些页面显示为灰色。

我已将页面设置为在 WooCommerce 会员资格购买后 X 天获得访问权限,但是我使用的代码根本不起作用。即使它应该返回 true,它也会返回 false。

有什么想法吗?

<?php 
     $restrict_th0 = wc_memberships_is_post_content_restricted(24);
     $restrict_th1 = wc_memberships_is_post_content_restricted(28);
     $restrict_th2 = wc_memberships_is_post_content_restricted(30);
?>

<ul id="menu-academy">
     <li>
     <?php if ( $restrict_th0 ) { } else { ?>
          <a href="<?php echo home_url(); ?>/URL HERE/">
     <?php } ?>
     <span class="module_no">0</span><span class="module_descript">MODULE DESCRIPTION<span class="module_access<?php if ( $restrict_th0 ) { ?> lock<?php } ?>">
     <i class="fa fa-2x fa-<?php if ( $restrict_th0 ) { } else { ?>un<?php } ?>lock<?php if ( $restrict_th0 ) { } else { ?>-alt<?php } ?>" aria-hidden="true"></i></span></span><?php if ( $restrict_th0 ) { } else { ?></a><?php } ?></li>

</ul

【问题讨论】:

  • 前几行是帖子 ID(即检查“Page ID 24”是否受到限制等)

标签: php wordpress woocommerce conditional woocommerce-memberships


【解决方案1】:

你最好使用这个条件:

if( wc_memberships_is_user_active_member( $membership_plan ) ) {
   // Displayed fully functional Menu
} else {
   // Greyed displayed inactive Menu
}

这适用于已订阅计划且订阅有效的活动登录用户。

$membership_plan 必须替换为会员计划 slug、帖子对象或相关帖子 ID。

之后您还可以使用wc_memberships_is_post_content_restricted(ID)is_page(ID) 进行进一步操作……

【讨论】:

    猜你喜欢
    • 2022-08-22
    • 2016-10-09
    • 2017-02-04
    • 2018-12-20
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    • 2017-12-09
    相关资源
    最近更新 更多