Skip to content

Instantly share code, notes, and snippets.

@JPry
Last active November 3, 2023 18:37
Show Gist options
  • Save JPry/ed3f472d537408bc276a128d200842a8 to your computer and use it in GitHub Desktop.
Save JPry/ed3f472d537408bc276a128d200842a8 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Delete all subscriptions.
* Plugin URI: https://gist.github.com/JPry/ed3f472d537408bc276a128d200842a8
* Description: PERMANENTLY delete all subscriptions.
* Version: 1.0
* Author: Jeremy Pry
* Author URI: http://jeremypry.com/
* License: GPL2
*/
// Prevent direct access to this file
if ( ! defined( 'ABSPATH' ) ) {
die( "You can't do anything by accessing this file directly." );
}
add_action( 'init', 'jpry_delete_all_subscriptions', 20 );
/**
* Delete all available subscriptions.
*
* WARNING: There is no going back. There is no undo.
*
* @author Jeremy Pry
*/
function jpry_delete_all_subscriptions() {
$subscriptions = wcs_get_subscriptions( array(
'subscriptions_per_page' => 1000,
) );
/** @var WC_Subscription $subscription */
foreach ( $subscriptions as $subscription ) {
// If you want to allow for all of the proper hooks to be triggered, uncomment the next line.
//$subscription->update_status( 'cancelled' );
// This is the point of no return. After ths line the subscription is gone.
wp_delete_post( $subscription->get_id(), true );
}
// Explicit cleanup.
unset( $subscriptions );
}
@bavamca
Copy link

bavamca commented Sep 20, 2018

Hi,
after using this one plugin , the site not get loaded
why it happens?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment