0

Is it possible to hide or show custom fields by user's role.

For example: I have custom field "wholesale_notice" and it have to be visible only for my "wholesale" user role.

Thanks

0

1 Answer 1

1

Yes, it is possible to hide or show custom fields by user's role. Use current_user_can() for finding current user role. This function returns true if current user has capability or role. For example your current user is "wholesale" then you can use like this:

<?php if( current_user_can('wholesale')) {  ?> 
    // stuff here for wholesale
<?php } ?>

For more reference check this: https://codex.wordpress.org/Function_Reference/current_user_can

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.