mermberfix logo x
The MemberFix Team’s got you covered.
Membership plugins

Change MemberMouse level, update PayKickStart subscription

membermouse paykickstart subscription

Table of Contents

Overview

MemberMouse is a great membership solution for a WordPress website and, recently, after I have wrote the MemberMouse integration with PayKickstart article, the same customer which we have here on MemberFix, requested a solution for users to be able to upgrade their membership directly from their Dashboard page on the website.

Shortly, this customer uses the MemberMouse membership plugin to protect his content, and PayKickstart (PKS) as his checkout and funnels solution.

So, in this case, PKS is the app which manages all of the members’ billing. So, for example, let’s say that you have a WordPress website which uses MemberMouse and PKS with 3 membership levels: “Bronze Membership”, “Gold Membership” and “Platinum Membership”.

We need a possibility for “Bronze Membership” users to be able to upgrade their membership level to “Gold Membership” or “Platinum Membership” directly from their account page on website. When they choose to buy “Gold Membership” or “Platinum Membership” then PKS records the payment and MemberMouse is notified and the membership level and bundle (if it is the case) are updated.

We will do this using our friend Zapier and here are the steps:

Solution

1 – Login to your Zapier account, click here and accept the private invitation to PayKickstart Zapier integration.

zapier accept invite - Change MemberMouse level, update PayKickStart subscription

2 – Then visit “Connected Accounts” inside of Zapier, type Pay in the top search box and you will be able to see “PayKickstart (1.0.0) By Invite”. Click on it.

paykickstart1 - Change MemberMouse level, update PayKickStart subscription

3 – A pop-up window will appear. Add Your PayKickstart API Key in Zapier. Your API Key can be found in the top right navigation “Platform Settings” of PayKickstart. Note: You must be on the Professional or Premium plan to use this feature.

allow zapier - Change MemberMouse level, update PayKickStart subscription

4 – On your Zapier account page click on top button “Make a Zap!”.

make a zap - Change MemberMouse level, update PayKickStart subscription

5 – Choose a trigger app by clicking on PayKickstart icon or by typing “PayKickstart” in the search field if the icon is not visible. Then click on “Continue” button.

choose trigger app - Change MemberMouse level, update PayKickStart subscription

6 – Choose New Order as trigger on the next page. Then click on “Continue” button.

choose trigger - Change MemberMouse level, update PayKickStart subscription

7 – On the next page you will see the PayKickstart + Zapier connection. Click on “Continue”.

zapier connect account - Change MemberMouse level, update PayKickStart subscription

8 – On the next page you will need to select the PayKickstart campaign and products.

pks campaign 1 - Change MemberMouse level, update PayKickStart subscription

9 – On the next page you see the successful test.

pks test - Change MemberMouse level, update PayKickStart subscription

10 – Next go to Action section of the Zap and choose “Webhooks” which it is listed under “Built-in Apps”.

choose action - Change MemberMouse level, update PayKickStart subscription

11 – On the next page select GET and click on “Continue” button.

webhooks get - Change MemberMouse level, update PayKickStart subscription

12 – The next page will need more work and I will explain this in more detail. You need access to your website FTP. Just duplicate the page.php file from your theme files and name it upgrade-test-page.php. Open upgrade-test-page.php and add this to the top of it:

<?php

/* Template Name: Upgrade Test */

?>

We have just created a template WordPress file.

13 – Go to your WordPress Dashboard and click on Pages => Add New. Name the page “Upgrade Test” and select Upgrade Test as page template. So the link to the page will be yourdomain.com/upgrade-test/.

upgrade - Change MemberMouse level, update PayKickStart subscription

14 – Go back to your Zapier page Action => Edit template and do the following settings:

zap get upgrade - Change MemberMouse level, update PayKickStart subscription

So, for the URL section just add the address to the page we have created on WordPress ( https://yourdomain.com/upgrade-test/ or http://yourdomain.com/upgrade-test/ ). Then we will select Product as the first parameter which we will need to send and name it “product”. The second parameter is Buyer Email and we will name it “buyer_email”.

15 – Now we will need to add some php code to the page template which we have created. Open upgrade-test-page.php and just below the opening <body> tag add the below code:

<?php

global $wpdb;

// get the two parameters from Zapier

$user_email = $_GET;

$membership_level = $_GET;

// get user ID from wp_users table

$user_id = $wpdb>get_var(“SELECT ID FROM wp_users WHERE user_email = ‘$user_email‘”);

// get current membership level ID from mm_user_data table

$current_membership_level_id = $wpdb>get_var(“SELECT membership_level_id FROM mm_user_data WHERE wp_user_id = ‘$user_id‘”);

if ( $current_membership_level_id > 0 ) {

// get current membership level ID from mm_user_data table

if ($membership_level == ‘Bronze Membership’ )
{
$membership_level_id = membership id here (a number);
}

if ($membership_level == ‘Gold Membership’ )

{
$membership_level_id = membership id here (a number);
}

if ($membership_level == ‘Platinum Membership’ )
{
$membership_level_id = membership id here (a number);
}

// check if current level is smaller than new level ( in the case where your memberships are set up in ASC order ) – in other case you can check if they are different

if ($current_membership_level_id < $membership_level_id) {

// add the new membership to the user in the database
if (($membership_level == ‘Gold Membership’))

{

$wpdb>update(
‘mm_user_data’,
array(
‘membership_level_id’ => membership id here (a number)
),
array( ‘wp_user_id’ => $user_id ),
array(
%d
),
array( %d )
);

} else if ($membership_level == ‘Platinum Membership’ )

{

$wpdb>update(
‘mm_user_data’,
array(
‘membership_level_id’ => membership id here (a number)
),
array( ‘wp_user_id’ => $user_id ),
array(
%d
),
array( %d )
);
}

// add the new bundle to the user in the database
if ($membership_level == ‘Gold Membership’ )

{

$wpdb>update(
‘mm_applied_bundles’,
array(
‘bundle_id’ => bundle id here (a number)
),
array( ‘access_type_id’ => $user_id ),
array(
%d
),
array( %d )
);

} else if ($membership_level == ‘Platinum Membership’ )

{

$wpdb>update(
‘mm_applied_bundles’,
array(
‘bundle_id’ => bundle id here (a number)
),
array( ‘access_type_id’ => $user_id ),
array(
%d
),
array( %d )
);
}

//NOW we need to cancel current Pay Kickstart subscription

// get current subscription ID from WP database (which it is the same as the subscription ID on PKS)

$subscription_id = $wpdb>get_var(“SELECT value FROM mm_custom_field_data WHERE user_id = ‘$user_id‘”);

$t=time();

//Set up API path and method
$base_url = “https://app.paykickstart.com/api/”;
$route = “subscriptions/cancel”;
$url = $base_url . $route;
$post = true;

//Create request data string
$data = http_build_query();

//var_dump($data);

//Execute cURL request
$ch = curl_init();
if ($post) {
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
} else {
    $url = $url . “?” . $data;
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$output = curl_exec($ch);
curl_close($ch);

}
}
?>

So basically the code above is inserting into the database the membership lever ID and Bundle ID for every user whenever a new order happens on PayKickstart. Then we cancel the current subscription on Pay Kickstart.

16. We are done! 🙂

You may also enjoy...

WordPress based membership sites have certain requirements, and make use of certain applications that, in my experience, makes most of the popular hosting providers a poor choice.
How to fix “background request blocked” error while using WordFence security plugin in conjunction with OptimizePress
Learn how to redirect users to different post-login pages depending on their current membership or even their past membership in WooCommerce!
How we manage our schedule using Airtable
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments