Many people would like to integrate Paid Memberships Pro with Gravity Forms. While we don’t have a tight integration available at this time, below is a simple code example that you can use to trigger a user’s membership level change as part of a Gravity Form submission.


Some things to consider…

  • This method will rely solely on the form requiring a user to be logged in, or that the form is a “user registration” form using the Gravity Forms user registration add on.
  • If your level is a paid level, you will need all of the appropriate subscription and gateway add ons for Gravity Forms. This method will not use the level’s Billing Details set up in PMPro. We’d advise only doing this if your level is free or simply a one time payment.
  • The payments will not show up as “orders” in Paid Memberships Pro, nor will they be part of your “Reports” in Paid Memberships Pro. The invoice records will all be stored in Gravity Forms admin pages, and the user’s Membership Account page will have no record of payment.

So this is a very specific use case, but it gives you an idea of how you might want to integrate with Gravity Forms… so here it is:

function my_gform_after_submission($entry, $form)
{
	if(!function_exists("pmpro_changeMembershipLevel"))
		return;
 
	global $current_user;
	$user_id = $current_user->ID;	
	pmpro_changeMembershipLevel( 1, $user_id );
}
add_action("gform_after_submission_1", "my_gform_after_submission", 10, 2);

This entry was posted by Kimberly Coleman in General and tagged . Bookmark the permalink. Last updated: April 1, 2014. Titled Assign or change a user’s membership level on Gravity Form submission

Comments (32)

Hey,
Thanks for this. I just have a couple of problems. The level does change but it doesn’t set the expiry date that I assigned to this level. It comes up with ‘Never’ under the Members List.

Also, I have two different Gravity forms, both once submitted to assign the same level. Do you know how I can set both gravity forms (ID 2 and 3) to this script.

I’m pretty much a novice at this!

Thanks for your help.

Maybe sure that $level_id is pointing to a real level of yours and that that level has an expiration date. Or you could set the “enddate” value specifically. Otherwise, follow up in our member forums and we can help you some more.

Couple questions.
1. Do I place this in my custom pmpro plugin?
3. Am I correct that the ‘1’ in your example [pmpro_changeMembershipLevel( 1, $user_id );] refers to the pmpro level the user will changing to?
4. What do the “10” and “2” refer to in your example [“my_gform_after_submission”, 10, 2);]

Thanks Jason (yes… I started to ask question to, but then found the answer) 🙂
Question though:
I got the code above to work with the Gravity Form Registration Add On, in that it registered the person, however, it did not assign the person the level ‘8,’ which is our free level. I placed the 8 in the right place in the code, as you indicated. However, it assigned them to no level. Is there something I am missing?

Probably because the code example above is using the user ID of the logged in user. In my case new registrants are not signed in, so I used get_user_by(‘login’, $entry[field# of username in my form]) instead. Works great.

Could you clarify what the code should be if the user isn’t logged in? In my case, I have a Gravity form where we are allowing one member to give a membership as a gift to another, so the logged-in user fills out the form and it creates another user via the User Registration add-on.

Here’s what I have – I have tried a few versions, including one where I was getting the user by email. The original tutorial for this post DOES work for giving a person a different membership level when the logged-in user submits the form, but this modification (based on spacebar’s comment above) does not. Could you help me figure out where I’m wrong?

`
function my_gform_create_member($entry, $form)
{
if(!function_exists(“pmpro_changeMembershipLevel”))
return;
$user_id = get_user_by(’email’, $entry[5]);
pmpro_changeMembershipLevel( 1, $user_id );
}
add_action(“gform_after_submission_8”, “my_gform_create_member”, 10, 2);
`

This should work as long as $entry[5] has the user_id from the created user in it. Maybe that id is stored somewhere else? Maybe there is a hook in the User Registration addon you can hook into to change the user’s membership level after being created.

Ok.It’s work with
function add_custom_user_meta( $user_id, $feed, $entry, $user_pass ) {
//update_user_meta( $user_id, ‘user_confirmation_number’, rgar( $entry, ‘1’ ) );
pmpro_changeMembershipLevel( 2, $user_id);
}
add_action( ‘gform_user_registered’, ‘add_custom_user_meta’, 10, 4 );

now I will try to update expiration date and some other stuff ^^

Jason any idea to link website id to pmro user (I use the gravity form “Multi-Site Creation on user-registration” function instead of pmpro-network and I need Pmro to know what website is used by the user )

function add_custom_user_meta( $user_id, $feed, $entry, $user_pass ) {

$level_id=2;
$level = pmpro_getLevel($level_id);
$custom_level = array(
‘user_id’ => $user_id,
‘membership_id’ => $level_id,
‘code_id’ => ”,
‘initial_payment’ => $level->initial_payment,
‘billing_amount’ => $level->billing_amount,
‘cycle_number’ => $level->cycle_number,
‘cycle_period’ => $level->cycle_period,
‘billing_limit’ => $level->billing_limit,
‘trial_amount’ => $level->trial_amount,
‘trial_limit’ => $level->trial_limit,
‘startdate’ => “‘” . current_time(‘mysql’) . “‘”,
‘enddate’ => date(“Y-m-d”, strtotime(“+” . $level->expiration_number . ” ” . $level->expiration_period)),
);

pmpro_changeMembershipLevel($custom_level, $user_id);

}
add_action( ‘gform_user_registered’, ‘add_custom_user_meta’, 10, 4 );

Et voila! Pmpro and gravity form are both very fexible!
function update_pmpron_blog_id( $site_id, $user_id, $entry, $feed, $password ) {

update_user_meta( $user_id, ‘pmpron_blog_id’, $site_id );

}
add_action( ‘gform_site_created’, ‘update_pmpron_blog_id’, 10, 5 );

When adding this code it says – ” Not paying.” I created another level with same pricing to help sort between prospect and new clients. The pricing is exactly the same so I’d like to just have their level changed.

If you view the membership level on the edit user page, we added a little helper to show the pricing from the last PMPro checkout. If you manually change a user or use code like this, the pricing information isn’t known. So we say “not paying” although that might not be technically true.

Although when you call the pmpro_changeMembershipLevel function it will cancel associated PMPro subscriptions by default. You can disable this with this filter:
https://www.paidmembershipspro.com/hook/pmpro_cancel_previous_subscriptions/

You can unhook that filter before and turn it back on after like this:

`
add_filter(‘pmpro_cancel_previous_subscriptions’, ‘__return_false’);
pmpro_changeMembershipLevel( 1, $user_id );
remove_filter(‘pmpro_cancel_previous_subscriptions’, ‘__return_false’);
`

The code on this page didn’t work well for me. My friend Tom Harrigan helped me come up with something better that worked:

`
function my_gform_after_submission( $user_id, $feed, $entry ) {
if ( ! function_exists( ‘pmpro_changeMembershipLevel’ ) ) {
return;
}
if ( 11 == $entry[‘form_id’] ) {
pmpro_changeMembershipLevel( 4, $user_id );
}
}
add_action( ‘gform_user_registered’, ‘my_gform_after_submission’, 10, 3 );
`

Where 11 is the form ID, and 4 is the membership level ID. Place code in functions.php or custom PMPro plugin.

Hi @toddcav and Jason,

I’m trying out:

function my_gform_after_submission( $user_id, $feed, $entry ) {
if ( ! function_exists( ‘pmpro_changeMembershipLevel’ ) ) {
return;
}
if ( 9 == $entry[‘form_id’] ) {
pmpro_changeMembershipLevel( 2, $user_id );
}
}
add_action( ‘gform_user_registered’, ‘my_gform_after_submission’, 10, 3 );

but doesn’t appear to be working – do I need to change the (10,3) to anything else?

and how to modify the above so I can include two forms?
also need:
if ( 5 == $entry[‘form_id’] ) {
pmpro_changeMembershipLevel( 4, $user_id );
}

We’d be able to help you better in the member forums. With access to your site, we could tweak this for you. Let the forum thread know that I mentioned that.

The “10,3” there doesn’t need to change. It tells the hook to fire on default priority 10 and that the hooked function has 3 parameters.

The part that needs to change is the 9 == $entry… It assume 9 is the ID for your form. Also the 2 in pmpro_changeMembershipLevel means level 2.

Hello,

Does codes doent seem to work for me!
I have a membership site where I have a FREE membership. I would like to have user register in my site with a gravity form (and register user add on) and activate the FREE membership when they create the account.

Can you help me out? The gravity form ID is 1 and the free membership level is 4

Hi, I am using paid membership pro, theme my login and Gravity Forms with “User registration” add-on.

My subscription form are created with Gravity Forms. My users can subscribe with no problem but when they want to login (the login page just contain the theme my login shortcode), they arrive on a error 500 page (but if they refresh the error 500 page they finally arrive on the good page).

Below the error i found in my error log files (the first line is when the user created is account), next lines are when he try to login :

[13-Oct-2017 09:31:10 UTC] PHP Warning: Creating default object from empty value in /home/rciziapqb/public_html/wp-content/plugins/pmpro-register-helper/pmpro-register-helper.php on line 578
[13-Oct-2017 09:39:58 UTC] PHP Warning: Illegal string offset ‘last’ in /home/rciziapqb/public_html/wp-content/plugins/paid-memberships-pro/adminpages/reports/login.php on line 402
[13-Oct-2017 09:39:58 UTC] PHP Warning: Illegal string offset ‘alltime’ in /home/rciziapqb/public_html/wp-content/plugins/paid-memberships-pro/adminpages/reports/login.php on line 403
[13-Oct-2017 09:39:58 UTC] PHP Fatal error: Uncaught Error: Cannot increment/decrement overloaded objects nor string offsets in /home/rciziapqb/public_html/wp-content/plugins/paid-memberships-pro/adminpages/reports/login.php:403
Stack trace:
#0 /home/rciziapqb/public_html/wp-includes/class-wp-hook.php(300): pmpro_report_login_wp_login(‘jonathan005’)
#1 /home/rciziapqb/public_html/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array)
#2 /home/rciziapqb/public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#3 /home/rciziapqb/public_html/wp-includes/user.php(104): do_action(‘wp_login’, ‘jonathan005’, Object(WP_User))
#4 /home/rciziapqb/public_html/wp-content/plugins/theme-my-login/includes/class-theme-my-login.php(482): wp_signon(Array, true)
#5 /home/rciziapqb/public_html/wp-includes/class-wp-hook.php(298): Theme_My_Login->template_redirect(”)
#6 /home/rciziapqb/public_html/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array)
#7 /home/rciziapqb/public_html/wp-includes/plugin.php(453): WP_Hook->do_action( in /home/rciziapqb/public_html/wp-content/plugins/paid-memberships-pro/adminpages/reports/login.php on line 403

Did you know what can be the error ?

Anyone wanting to know how to assign a membership level on new account creation through GravityForms, just paste the following into your themes functions.php

/* ————————————————————
:: ADD DEFAULT LEVEL AT PMPPRO
————————————————————— */
add_action(‘user_register’, ‘kleo_pmpro_default_level’);
function kleo_pmpro_default_level($user_id) {
pmpro_changeMembershipLevel(1,$user_id);
}

Leave a Reply

Your email address will not be published. Required fields are marked *