Home / Archive / MemberPress: Turn Off Auto-Rebill for Offline Gateway
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Turn Off Auto-Rebill for Offline Gateway

Some integrations - like Mail Chimp - require auto-rebill to be stopped before they do their thing - like removing users from a list. But the Offline gateway doesn’t turn off the auto rebill. So this snippet will turn off auto rebill for the offline gateway when a transaction expires - and turn it back on when a new completed transaction is registered.

Code Preview
php
<?php
//Turn off Auto rebill for offline gateway if a transactions expires
function turn_off_auto_rebill_offline_gateway( $txn, $sub_status ) {
	if ( $txn->payment_method() instanceof MeprArtificialGateway && $sub = $txn->subscription() ) {
		$sub->status = MeprSubscription::$cancelled_str;
		$sub->store();
	}
}
add_action( 'mepr-transaction-expired', 'turn_off_auto_rebill_offline_gateway', 9, 2 ); //Make sure it runs earlier than other MP stuff
//If a transaction is completed on an offline gateway subscription - turn auto rebill back on
function turn_on_auto_rebill_offline_gateway( $txn ) {
	if ( $txn->payment_method() instanceof MeprArtificialGateway && $sub = $txn->subscription() ) {
		$sub->status = MeprSubscription::$active_str;
		$sub->store();
	}
}
add_action( 'mepr-txn-status-complete', 'turn_on_auto_rebill_offline_gateway' );

Comments

Add a Comment