Last active
April 2, 2025 00:15
-
-
Save barryhughes/42005be4ed0e2a1e8186630de56cb6ca to your computer and use it in GitHub Desktop.
Generate x renewal orders for an existing subscription.
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 | |
/** | |
* This script can be used to quickly add a stack of renewals | |
* to an existing subscription. Can be useful when testing | |
* scalability concerns for WooCommerce Subscriptions. | |
*/ | |
function generate_renewal_order_for_subscription( $subscription_id ) { | |
$subscription = new WC_Subscription( $subscription_id ); | |
// We can't successfully trigger creation of a renewal unless the subscription | |
// is active, which may not initially be the case. | |
if ( 'active' !== $subscription->get_status() ) { | |
$subscription->update_status( 'active' ); | |
} | |
// Try triggering a renewal. This also often sets the subscription to on-hold, | |
// so we again change the status. | |
WC_Subscriptions_Manager::prepare_renewal( $subscription_id ); | |
$subscription->update_status( 'active' ); | |
} | |
// Generate 100 renewals for the subscription (adjust the sub ID as needed). | |
for ( $i = 1; $i <= 100; $i++ ) { | |
generate_renewal_order_for_subscription( 1234 ); | |
print '.' . ( ( $i % 10 ) ? '' : PHP_EOL ); // Progress dots intended for CLI usage. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment