Hide Gravity Forms Field only for users with a specific Memberpress Subscription

379 Views Asked by At

We have a gravity form, and I'd like to be able to hide or show specific fields based on whether the user has a specific memberpress subscription. My overall approach was to use the HTML field to run a script to see if the user has a specific memberpress subscription and if so, populate a random field. I would then use that field for conditional logic on the fields I want to hide/show for users with the active memberpress subscription.

Based on this post, I see that I can check if a user already has active memberpress: How can I detect if user has subscribed Memberpress product already

But how can I then populate a value into a specific field of my form if the code returns true that user does have active memberpress subscription?

$mepr_user->is_active_on_membership( $membership_id ); // true or false
1

There are 1 best solutions below

0
On

If you're embedding HTML / JavaScript you can take advantage of the Available Shortcodes from MemberPress.

Just replace the membership number with the correct ID from MemberPress.

<script>
    document.addEventListener("DOMContentLoaded", function() {
        let isActive = '[mepr-active membership="123" ifallowed="show"]true[/mepr-active]' || false;
        document.getElementById('id_of_your_input_field').value = isActive;
    });
</script>