I have the following code that looks for certain woocommerce subscription statuses. I’m trying show a different message for each of the following statuses ‘cancelled’ and ‘paused’. Would you know how I can adapt this block of code to achieve that?

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

<?php echo ('has active subscription'); ?>

<?php } ?>

So I’m trying to see if I can have something similar to this following after the above block of code…

<?php if 'status' = 'paused' { ?>
<?php echo ('Your account has been paused ...'); ?>
<?php } ?>

Read more here: How to recode to allow targeting single status?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: