Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce会员资格:有条件限制内容检查_Php_Wordpress_Woocommerce_Conditional_Woocommerce Memberships - Fatal编程技术网

Php WooCommerce会员资格:有条件限制内容检查

Php WooCommerce会员资格:有条件限制内容检查,php,wordpress,woocommerce,conditional,woocommerce-memberships,Php,Wordpress,Woocommerce,Conditional,Woocommerce Memberships,我正在尝试制作一个页面链接菜单,人们一旦购买了会员资格(通过)就可以访问这些链接。我想让那些页面变灰,如果他们还没有访问权限的话 我已经将页面设置为在购买WooCommerce会员资格后X天获得访问权限,但是我使用的代码根本不起作用。它返回false,即使它应该返回true 有什么想法吗 <?php $restrict_th0 = wc_memberships_is_post_content_restricted(24); $restrict_th1 = wc_mem

我正在尝试制作一个页面链接菜单,人们一旦购买了会员资格(通过)就可以访问这些链接。我想让那些页面变灰,如果他们还没有访问权限的话

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

有什么想法吗

<?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


  • 您最好使用以下条件:

    if( wc_memberships_is_user_active_member( $membership_plan ) ) {
       // Displayed fully functional Menu
    } else {
       // Greyed displayed inactive Menu
    }
    
    这适用于已订阅计划且订阅有效的活动登录用户

    $membership\u plan
    必须由成员计划slug、post对象或相关post ID替换


    在您还可以使用
    wc\u会员资格\u is\u post\u content\u restricted(ID)
    is\u page(ID)
    进行进一步操作后…

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