Last active
December 11, 2015 16:49
-
-
Save supercleanse/4630456 to your computer and use it in GitHub Desktop.
This should work ... just make sure you change the id on line 18 to go along with the products you want to be setup as your lifetime + trials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: MemberPress Lifetime Trial | |
Plugin URI: http://memberpress.com | |
Description: Creates a lifetime subscription from a 1 year subscription + a *free* trial. This basically cancels the subscription after the first real payment | |
Version: 1.0.0 | |
Author: Caseproof, LLC | |
Author URI: http://caseproof.com | |
Text Domain: memberpress | |
Copyright: 2004-2013, Caseproof, LLC | |
*/ | |
add_action('mepr-txn-status-complete', 'mepr_lifetime_trial'); | |
function mepr_lifetime_trial($txn) { | |
// do this on the first real payment for | |
// product_id==whatever that aren't free or | |
// manual transactions and are attached to a subscription | |
if( $txn->product_id==456 and | |
$txn->txn_type==MeprTransaction::$payment_str and | |
$txn->status==MeprTransaction::$complete_str and | |
!in_array( $txn->gateway, | |
array( MeprTransaction::$free_gateway_str, | |
MeprTransaction::$manual_gateway_str ) ) ) | |
{ | |
// The first transaction for paid trials counts as a payment so in | |
// this scenario we want to only do this on the second payment method | |
if( $sub = $txn->subscription() and | |
$sub->trial_amount > 0.00 and | |
$sub->txn_count <= 1 ) | |
{ | |
return false; | |
} | |
// Update the transaction to have a never ending expiration date | |
MeprTransaction::update( $txn->id, $txn->amount, $txn->user_id, | |
$txn->product_id, $txn->txn_type, $txn->status, $txn->coupon_id, | |
$txn->response, $txn->trans_num, $txn->subscription_id, | |
$txn->gateway, $txn->created_at, '0000-00-00 00:00:00' ); | |
// Cancel the subscription | |
$pm = $txn->payment_method(); | |
$pm->process_cancel_subscription($sub->ID); | |
return true; | |
} | |
} | |
@cartpauj ... I finally got this updated. I haven't tested this code but it should look something like this.
I am getting an error when attempting to activate the plugin:
Parse error: syntax error, unexpected '}' in /wp-content/plugins/mepr_lifetime_trial.php on line 32
Line 31 is missing a semi colon
return false;
Added the semi-colon to the gist ...
I also think that the action needs to be changed to this
add_action('mepr-txn-status-complete', 'mepr_lifetime_trial', 10, 1);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to use multiple products change line 18 to something like
if(in_array($txn->product_id, array(456, 123, 309)) and