Skip to content

Instantly share code, notes, and snippets.

@NickGreen
Last active May 17, 2019 15:37
Show Gist options
  • Save NickGreen/fd529c695d5f5b11c38823ac726274e3 to your computer and use it in GitHub Desktop.
Save NickGreen/fd529c695d5f5b11c38823ac726274e3 to your computer and use it in GitHub Desktop.
Cancel all of your subs
<?php
/**
* Plugin Name: Cancel all subscriptions.
* Description: Cancel all subscriptions.
* Version: 1.0
*/
// Prevent direct access to this file
if ( ! defined( 'ABSPATH' ) ) {
die( "You can't do anything by accessing this file directly." );
}
add_action( 'init', 'cancel_all_subscriptions', 20 );
function cancel_all_subscriptions() {
$subscriptions = wcs_get_subscriptions( array(
'subscriptions_per_page' => -1,
) );
foreach ( $subscriptions as $subscription ) {
if ( $subscription->can_be_updated_to( 'cancelled' ) ) {
$subscription->update_status( 'cancelled', 'Subscription cancelled via bulk cancellation.' );
}
}
unset( $subscriptions );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment