Using multiple if else to check for content and member status

I am trying to check if a user is logged in as a member and also if a meta field in a WordPress custom post type has content and then need to display content based on 4 possible outcomes. I am using WordPress membership plugin woomembers

  1. user is logged in as a member and content exists – display content
  2. user is logged in as a member and content field is empty – display nothing
  3. user is not a member and content exists – display some content and sign up
  4. user is not a member and no content exists – display sign up

I have this code partly working but can’t get item 3 to work?

The code I have is:

<?php $meta_content_field = get_post_meta($post->ID, "meta-content-field", 
$single = true);

   if (wc_memberships_get_user_active_memberships() && 
   $meta_lighting_diagram != '') { 

       // Active member and has content- do something here

       ?>
       html content here

   <?php
   } elseif (wc_memberships_get_user_active_memberships() && 
   empty($meta_content_field) ) {

        // No content but active member - do something here
        echo "No content but active member";

   } elseif ( ! empty( wc_memberships_get_user_active_memberships() ) && 
   ($meta_content_field) ) {

       // content but non-member - do something here - this is not working? 
       echo "Has content but NOT active member";    

   } else {  

        // Non-member - do something here ?>
        html content here                                       

  <?php }
  ?>

Read more here: Using multiple if else to check for content and member status

Leave a Reply

Your email address will not be published. Required fields are marked *