Search

Testing WooCommerce Subscriptions with Hooks and WCS_DEBUG

Listen to this article

code-snippets-woocommerceWooCommerce Subscriptions is quite a popular plugin. In fact it’s the most popular WooCommerce extension.

You can stay assured that the developers ensure every version released is stable. So, there isn’t really a reason to test it. :-p

But, if you still want to check if all’s working right, or if you want to test a functionality you’ve built on top of it, here are some tips which can help!

Using Actions Hooks

Like any good plugin, WooCommerce Subscriptions has a bunch of hooks and filters which you can use to extend its functionality. But these hooks can come in handy even if you want to test the working of the plugin.

  • Subscription Expiration hooks
    • The ‘scheduled_subscription_expiration’ hook can be used to trigger an action when the subscription is about to end.
    • The ‘subscription_expired’ hook is called when the subscription expires.
    • If a user has canceled a subscription, ‘subscription_end_of_prepaid_term’ hook is triggered when the subscription was due to be expired.
  • Change in Subscription Status hooks
    • The ‘activated_subscription’ hook is called when a subscription order is marked complete and the subscription is activated.
    • The ‘cancelled_subscription’ hook is called when a subscription has been canceled by the admin (or store manager), payment gateway or the user.
    • The ‘subscription_put_on-hold’ hook is called when a subscription is suspended by the admin (or store manager), or a customer.

As a developer, you can use any of these hooks to test the system during debugging.

But there is one other way too.

Instead of waiting for the subscription plugin to run its natural course, while testing, you can trigger the needed actions at will.

Using WCS_DEBUG

You see, for a subscription to expire naturally, the minimum duration a subscription can be setup is 24 hours. That’s too long a time to wait, when something needs to be tested immediately. Here, you can use the WCS_DEBUG variable.

WooCommerce Subscriptions provides the WCS_DEBUG variable that unleashes a wide range of options which can be very handy when testing. Here’s what you would need to do:

  • Go to your wp-config file and set WP_DEBUG to true
  • Then add the following
if ( ! defined( 'WCS_DEBUG' ) ) {
define( 'WCS_DEBUG', true );
}

Remember to save your changes made.

Once this is done, you should notice a ‘Scheduled Action‘ sub-menu under Tools in your admin panel.

wcs_debug_true_options

Here you should see a list of all the order actions scheduled to be fired at the end of a subscription period. Now, you can quickly search for your particular order and end the subscription by hitting ‘Run‘.

Note: If the order is of type recurring then a new scheduled action will be created with same order id.

And there you go!

You have an easy way to test the WooCommerce Scheduler plugin. Now in case you come up with any issues the right forum to raise a support request would be the plugin’s support forums. But, if you have any questions regarding the content you’ve read in this article, you can shoot me a question and I’ll try my best to help.

That’s all for now.

Happy debugging!

Nikhil Vichare

Nikhil Vichare

Leave a Reply

Your email address will not be published. Required fields are marked *

Get The Latest Updates

Subscribe to our Newsletter

A key to unlock the world of open-source. We promise not to spam your inbox.

Suggested Reads

WordPress Development

Custom WordPress Solutions, for You

LearnDash Development

Custom LearnDash Solutions, for You

WooCommerce Development

Custom WooCommerce Solutions, for You

WordPress Plugins

Scale your WordPress Business

WooCommerce Plugins

Scale your WooCommerce Business

LearnDash Plugins

Scale your LearnDash Business

Label

Title

Subtext

Label

Title

Subtext

Join our 55,000+ Subscribers

    The Wisdm Digest delivers all the latest news, and resources from the world of open-source businesses to your inbox.

    Suggested Reads