Home / Admin / MemberPress: Bulk Delete All Expired Subscriptions
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Bulk Delete All Expired Subscriptions

Running this code snippet will delete all expired and canceled subscriptions in bulk each time the WP Admin Dashboard is reloaded.

Since this process can use a lot of server resources (e.g. if there are many subscriptions), the suggested steps for using this code snippet are:

1. Add the code to your website.
2. Reload the Dashboard once.
3. Remove the code.

Repeat these steps any time when needed.

Code Preview
php
<?php
function mepr_delete_expired_txns() {
  $subscriptions = MeprSubscription::get_all();
  if( is_array( $subscriptions ) && !empty( $subscriptions ) ) {
    foreach( $subscriptions as $subscription ) {
      $subscription = new MeprSubscription( $subscription->id );
      if( $subscription->is_cancelled() && $subscription->is_expired() ) {
        $subscription->destroy();
      }
    }
  }
}
add_action( 'admin_init', 'mepr_delete_expired_txns' );

Comments

Add a Comment