Home / Archive / MemberPress: Expire Subscription Immediately After Subscription Is Canceled
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Expire Subscription Immediately After Subscription Is Canceled

By default, canceling subscriptions prevents future charges, but it does not end existing subscriptions, which allow members access until the expiry date. Applying this code snippet will expire a member’s subscription when canceled by setting the transaction expiration date to the past. This will immediately prevent members from accessing protected content.

You can adjust the past date, which will be set as a transaction expiry date for all canceled transactions, by editing the date on this line:

$wpdb->update( $wpdb->prefix.'mepr_transactions', array( "expires_at" => "2024-01-01

Code Preview
php
<?php
function mepr_capture_stopped_sub( $event ) {
  global $wpdb;
  $subscription = $event->get_data();
  $wpdb->update( $wpdb->prefix.'mepr_transactions', array( "expires_at" => "2024-01-01 23:59:59" ), array( "subscription_id" => $subscription->id, "status" => "complete" ) );
  
}
add_action( 'mepr-event-subscription-stopped', 'mepr_capture_stopped_sub' );

Comments

Add a Comment