Hiding private Custom Fields made by CustomPress by Membership 2 Pro

I have set up some private Custom fields which I want to hide by Membership 2 Pro plugin. Please suggest how can I do that?

  • Ash

    Hello Liz

    Here is the code you can try:

    $user_id = get_current_user_id();
    $member = MS_Factory::load( 'MS_Model_Member', $user_id );
    $membership_id = 10;
    
    if( $member->has_membership( $membership_id ) ) {
    	// Add the code here that you allow to the members which membership id = 10;
    }

    If you use the following

    $member->has_membership()

    instead of

    $member->has_membership( $membership_id )

    That will for all members who has at least one subscription.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

  • Nithin

    Hi Liz,

    Hope you are doing good today. :slight_smile:

    Could I know on which exact file you are adding the above code? And how are the custom fields added in your site, and on which page in the fronted you are trying to hide? A link to the page would be helpful. If you are adding the code inside a template please share the code for template file too.

    In your screenshot the way "Testing Text" is added is incorrect for a PHP code. Also, I could see the following lines:

    $member = MS_Factory::load( 'MS_Model_Member', $user_id );
    
    if( $member->has_membership( $membership_id ) ) {

    In your screenshot as:

    $member = MS_Factory::load( &#039MS_Model_Member#&039, $user_id );
    if( $member-#gt;has_membership( $membership_id ) ) {

    Which should be corrected. The code would be as follows:

    $user_id = get_current_user_id();
    $member = MS_Factory::load( 'MS_Model_Member', $user_id );
    $membership_id = 10;
    
    if( $member->has_membership( $membership_id ) ) {
    	// Add the custom fields code in here that you allow to the members with membership id = 10;
    echo "Testing text";
    }

    If you still have issues, please provide more details, so that we could give a closer look.

    Regards,
    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.