# 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](https://github.com/mattallan) for this one. ## Installation To install: 1. Download the latest version of the plugin [here](https://github.com/Prospress/woocommerce-subscriptions-reschedule-next-payment-dates/archive/master.zip) 1. Go to **Plugins > Add New > Upload** administration screen on your WordPress site 1. Select the ZIP file you just downloaded 1. Click **Install Now** 1. 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-`. ### 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-`. 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-`. 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](https://github.com/Prospress/wcs-reschedule-next-payment-dates/blob/master/wcs-reschedule-next-payment-dates.php#L60) to something else to get around browser redirect limits ref: [http://stackoverflow.com/questions/9384474/in-chrome-how-many-redirects-are-too-many](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. ---