Skip to content

Instantly share code, notes, and snippets.

@govindak
Forked from supercleanse/auto_enroll.php
Created August 17, 2016 19:39
Show Gist options
  • Save govindak/525d01b200558ccd1689730d7fd4e8c5 to your computer and use it in GitHub Desktop.
Save govindak/525d01b200558ccd1689730d7fd4e8c5 to your computer and use it in GitHub Desktop.
Automatically create a lifetime transaction for a specific product each time a user registers.
<?php
if(is_plugin_active('memberpress/memberpress.php')) {
add_action( 'user_register', 'mp_auto_enroll' );
//add_action( 'gform_user_registered', 'mp_auto_enroll', 10, 4 );
function mp_auto_enroll($user_id, $user_config=array(), $entry='', $user_pass='') {
$txn = new MeprTransaction();
$txn->user_id = $user_id;
$txn->product_id = 8; // TODO: Make sure you change this value to whatever the product_id will be
$txn->trans_num = uniqid();
$txn->status = MeprTransaction::$complete_str;
$txn->gateway = MeprTransaction::$free_gateway_str;
$txn->expires_at = 0; // 0 = Lifetime, null = product default expiration
$txn->store();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment