How to Disable WooCommerce Action Scheduler / Subscriptions on a Staging Site

Suppose you use the “WooCommerce Subscriptions” plugin or any other subscription plugin to charge your customers recurring. In that case, you definitely want to stop your customers from being automatically charged again — at worse, multiple times during testing — from your staging site.

You also want to stop executing other scheduled events on your staging site, like sending out expiration license reminder emails. To disable these automatic events, you will need to disable the background action scheduler, which is used by WooCommerce.

You have two options to disable Subscriptions and to disable the WooCommerce action scheduler:

Disable WooCommerce Action Scheduler for Subscriptions by Using a Plugin

Install and activate the free plugin Action Scheduler – Disable Default Runner.

Disable WooCommerce Action Scheduler for Subscriptions by using code

Add the code below into the functions.php or a separate plugin:

PHP
function PREFIX_disable_action_scheduler() {
    if ( class_exists( 'ActionScheduler' ) ) {
        remove_action( 'action_scheduler_run_queue', array( ActionScheduler::runner(), 'run' ));
    }
}
add_action( 'init', 'PREFIX_disable_action_scheduler', 10 );

Note: Change PREFIX to something unique.
This plugin/code disables all events in the WooCommerce action scheduler library that are used by WooCommerce plugins, so scheduled events like recurring payments or sending out emails will be disabled for WooCommerce and all of its add-ons.

For more information, check out this article.

Updated on June 4, 2024