Last active
May 17, 2019 15:37
-
-
Save NickGreen/fd529c695d5f5b11c38823ac726274e3 to your computer and use it in GitHub Desktop.
Cancel all of your subs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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