WooCommerce Memberships: Conditional check if restrictions are disabled

369 Views Asked by At

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!

0

There are 0 best solutions below