Php 如何重新编码以允许目标单一状态?

Php 如何重新编码以允许目标单一状态?,php,wordpress,Php,Wordpress,我有以下代码查找某些woocommerce订阅状态。我正在尝试为以下状态“已取消”和“已暂停”显示不同的消息。您知道我如何调整这段代码来实现这一点吗 <?php function can_user_access_content($user_id,$post_id){ //check if there's a force public on this content if(get_post_meta($post_id,'_wc_memberships_force_p

我有以下代码查找某些woocommerce订阅状态。我正在尝试为以下状态“已取消”和“已暂停”显示不同的消息。您知道我如何调整这段代码来实现这一点吗

<?php
function can_user_access_content($user_id,$post_id){

    //check if there's a force public on this content    
    if(get_post_meta($post_id,'_wc_memberships_force_public',true) == 'yes') 
        return true;
    $args = array( 'status' => array( 'active','complimentary'));


    $plans = wc_memberships_get_user_memberships( $user_id, $args );
    $user_plans = array();
    if (is_array($plans)) {
        foreach ($plans as $plan) {
            array_push($user_plans,$plan->plan_id);
        }
    }
    $rules = wc_memberships()->get_rules_instance()->get_post_content_restriction_rules( $post_id );

    foreach ($rules as $rule) {
        if(in_array($rule->get_membership_plan_id(), $user_plans)){
            return true;
        }
    }       
    return false;
}

if (can_user_access_content(get_current_user_id(),$post->ID)) {
    echo ('has active subscription'); 
} 
?>


我不知道您的代码具体是什么,但请尝试返回您的状态(首选int),而不是true/false。为自己定义什么状态为false(通常类似于-1)。然后你可以使用这个返回值来检查状态。我不知道你的代码是做什么的,但是试着返回你的状态(最好是int),而不是true/false。为自己定义什么状态为false(通常类似于-1)。然后可以使用此返回值检查状态。
<?php if 'status' = 'paused' { ?>
<?php echo ('Your account has been paused ...'); ?>
<?php } ?>