0

This is a question about the membership plugin for WooCommerce: I want to hide post feature images for non-members using the plugin. Content is restricted by categories, this is the code I have so far:

// if post content is restricted
if ( wc_memberships_is_post_content_restricted() ) {
    // check if user has membership
    $user_id = get_current_user_id();
    if ( wc_memberships_is_user_active_member( $user_id, 'package_1' ) ||
         wc_memberships_is_user_active_member( $user_id, 'package_2' ) || 
         wc_memberships_is_user_active_member( $user_id, 'package_3' ) ) { 
            // Include featured image
    } else {
        echo 'Members only';
    }   
}

This code works but needs to be extended with a conditional for individual posts with disabled restrictions, ie free/public posts. Something like "if free, include feature image for non-members". But I can't find any information about conditional statements for the post with disabled restrictions in the docs.

Any help appreciated, thanks!

mujuonly
  • 11,370
  • 5
  • 45
  • 75
george
  • 167
  • 1
  • 4
  • 16
  • You just need to add an `else` to the main `if` statement where you will have all non restricted content cases (free and public posts)… **Note:** In your code there is a repetition in the second `if` statement condition (2 times `'package_2'`)… so you could remove one of them, and you will get the same. – LoicTheAztec Dec 26 '17 at 01:44
  • 1
    Ah, fixed the package name typo, thanks. Listing free/public posts in another if-statement would be a fine solution. But I am dealing with a LOT of posts so I was searching for a more general way to handle this. Something like `if ( wc_memberships_is_post_disabled_restrictions() )`, which doesn't seem to exist. – george Dec 26 '17 at 07:22

0 Answers0