Skip to content

Instantly share code, notes, and snippets.

@james-allan
Created July 18, 2018 01:04
Show Gist options
  • Save james-allan/aefcadf74c63f7416addda41c20eec72 to your computer and use it in GitHub Desktop.
Save james-allan/aefcadf74c63f7416addda41c20eec72 to your computer and use it in GitHub Desktop.
woocommerce-subscriptions-reset-next-payment-dates README

WooCommerce Subscriptions - Reset Next Payment Dates

A helper plugin for resetting all the next payment dates and pushing them back 1 minute.

Helps solve issues resulting in duplicate subscription renewal payments due to timezones.

All props go to @mattallan for this one.

Installation

To install:

  1. Download the latest version of the plugin here
  2. Go to Plugins > Add New > Upload administration screen on your WordPress site
  3. Select the ZIP file you just downloaded
  4. Click Install Now
  5. Click Activate

Important

Please test on a dev/staging site and be sure to backup first. Please, no cowboys.

Usage

Once activated the plugin has three modes of operation:

  1. Log: log the subscriptions that will be reset
  2. Reset and Rollback: actually reset the subscription dates, but rollback the changes to test the actual performance
  3. Reset Dates: actually reset the subscription dates

We recommend running Log first and checking subscriptions prior to considering running Update.

You can initiate each of these modes via the Plugin Action Links below the plugins name on the Plugins administration screen.

Log Mode

To generate a list of subscriptions that will be updated, from the WordPress Admin Dashboard navigate to the plugin page and click the Log the reset (does not update anything) plugin action link.

Once the page completes loading you'll be directed to the WooCommerce System Status log viewer page and can access the log file timezone-next-payment-date-fixer-<random string>.

Reset and Rollback Mode

To test the update process we've also added the ability to run the update process and the roll back the changes. From the WordPress Admin Dashboard navigate to the plugin page and click the Reset and rollback plugin action link.

Once the page completes loading you'll be directed to the WooCommerce System Status log viewer page and can access the log file timezone-next-payment-date-fixer-<random string>.

The subscriptions will not be updated.

Reset Mode

Please ensure you test and backup before running Update on a production site/environment

To update the next payment dates (i.e. to those values identified in log mode), from the WordPress Admin Dashboard navigate to the plugin page and click the RESET THE NEXT PAYMENT DATES! plugin action link.

Once the page completes loading you'll be directed to the WooCommerce System Status log viewer page and can access the log file timezone-next-payment-date-fixer-<random string>.

The subscriptions will be updated.

Restricting Subscriptions to Update

By default, all active subscriptions will have their dates reset. If you wish to restrict the reset to only specific subscriptions, you can define a constant array containing those subscription IDs.

For example, to restrict the reset to only subscriptions 1, 2 and 3, the following snippet can be added to the theme's functions.php file temporarily:

define( 'WCS_SUBSCRIPTION_IDS_FOR_DATE_RESET', array( 1, 2, 3 ) );

Tweaking Batch Size

Depending on the number of active subscriptions on the site AND what browser you are using you may need to modify the batch size from 10 to something else to get around browser redirect limits ref: http://stackoverflow.com/questions/9384474/in-chrome-how-many-redirects-are-too-many.

For example using Firefox to run the update on a site with 561 active subscriptions you would need a batch size of 30 (561/30 = 18.7) to safely get under the 20 redirect limit in the browser. Leaving it as 10 results in error message and process will not finish.


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