One of our MemberFix customers recently came to us with a unique use case in which she wanted to send pre-populated affiliate ID values from her core website, to an affiliate partner’s website. The affiliate partner’s website already had tech that would then grab the affiliate ID for their referral program tracking.
In our customer’s words:
Affiliates that we work with will also receive commissions through our partners and we need a way to track this internally. We have our partners set up so that when a link is clicked it has a CID code on the link and from that point it’s being tracked (we don’t have to do anything else – our partner is doing all the tracking at that point).
So, we need a way for the member to always be associated with that affiliate (the affiliate will also receive lifetime commissions on that member). My thought is we can do this by tracking the Affiliate #. Put a hidden field on MemberPress that will automatically populate with the affiliate # when they register. And what is the meta data field name that can then be used as the CID?
This particularly savvy customer had the right idea!
The core website has the following apps:
- The MemberPress WordPress membership plugin
- The AffiliateWP affiliate plugin for WordPress (with several add-ons active)
- Gravity Forms forms plugin
- The Lifetime Commissions add-on for AffiliateWP
- The Cookie Monster WordPress plugin (free)
Shortly the whole process is this:
- An user subscribes to her website and becomes a MemberPress member.
- The registration form for the user it is a Gravity Forms one with a hidden input field for the case when the new user was referred by an affiliate, which means that the new user landed on customer’s website from a link like this: https://yourwebsite.com/?mepr_affiliate=77 where “mepr_affiliate” is the ID of the affiliate which referred the new user. Then the Gravity Forms hidden input field is added to the database.
- MemberPress needs to be connected to AffiliateWP and AffiliateWP needs to be connected to Gravity Forms. I will explain below how we can easily do that.
- The the final part where the whole magic happens is that the customer has a page on the website which it is accessed by the MemberPress users and there is a form which every member can submit it and this will make the ID of the affiliate which referred the member is sent to an external website. As I said above this is needed for the referral program tracking.
Let’s see all the steps in more detail!
MemberPress integration with AffiliateWP
First of all MemberPress needs to be integrated with AffiliateWP and all you need to do is go to Affiliates > Settings > Integrations and check the MemberPress box:
Once enabled, AffiliateWP will automatically generate referral records when a customer successfully registers for your site after clicking on a referral link.
AffiliateWP integration with Gravity Forms
For this integration we will use Affiliate Forms For Gravity Forms add-on. After you install the add-on just go again to Affiliates > Settings > Integrations and check the Gravity Form box as you have seen in the above image. When you build the form with Gravity Forms you are able to add an input hidden field like in the below image:
“mepr_affiliate” is the URL variable for AffiliateWP referral URLs which can be defined in AffiliateWP > Settings > General as shown below:
So, for example, if a user lands on the registration form page from a link like this – https://yourwebsite.com/?mepr_affiliate=77 – the affiliate ID which referred this user is added to the database. If there is no parameter, then the “mepr_affiliate” hidden field will be empty.
Creating the form and WordPress PHP schortcode
Our customer (the vendor of this affiliate program) has a form on her site which is submitted to an external website that receives one of the parameters. The form looks something like this:
<input name=“mepraff” type=“hidden” value=“77” />
<button type=“submit”>SUBMIT FORM</button>
The objective was to dynamically update this form, for every visiting user, with the corresponding affiliate ID of the affiliate who referred them (the “mepraff” input in the above form corresponds to “mepr_affiliate” from the database). To achieve this functionality we used WordPress shortcodes and a bit of custom code in the functions.php file on the site that has MemberPress installed.
To that end, I wrote a function that shows the shortcode:
// retrieve the current user object
$current_user = wp_get_current_user();
// get user ID
$meta = get_user_meta( $current_user->ID );
// get the ID of the affiliate who referred user
$meta_mepr = $meta[“mepr_affiliate”];
// return hidden filed line for the form
return ‘<input name=”mepraff” type=”hidden” value=”‘.$meta_mepr.‘” />’;
Then I added the form code on the web page, and inserted the required shortcode (in bold below) directly into the form code:
<button type=“submit”>SUBMIT FORM</button>
Now when a given user is logged in, the function above will pull that user’s “mepr_affiliate” field value from the user database and populate the “mepraff” hidden field in the form with that value. Thus, when the form is submitted to the external website, the “mepraff” hidden field is sent there, and it can be manipulated in the external website in whatever way is required.
Questions, comments, concerns? Leave your thoughts below and we’ll be around to lend a hand. 🙂
I’m a web and graphic designer. I have an extensive experience in WordPress and I like working here at MemberFix.