Attempting to speed up WooCommerce Subscriptions admin

If you use WooCommerce along with their WooCommerce Subscriptions plugin you will probably notice the site becomes slow after a number of subscribers. As I wrote in a previous article, there are some tricks that may make it faster.

In this article I will present some code which might help with speeding up some pages which use lots of queries.

User’s active subscriptions count

If you ever used the Query Monitor plugin you probably noticed that on the Users list, even when loading 20 users WordPress does many queries ( hundreds ). With WooCommerce Subscriptions enabled there is one query which is especially resource expensive. That’s the query used to populate the “Active subscriber” column. You can go ahead and remove that if you don’t use it because you can also filter the users by the “subscriber” role. So here’s the code to do that:

// remove the subscription column in users table
remove_filter( 'manage_users_columns', 'WC_Subscriptions_Admin::add_user_columns', 11 );
remove_filter( 'manage_users_custom_column', 'WC_Subscriptions_Admin::user_column_values', 11 );

Comments count

Another very expensive query which I found might slow your website down if you have lots of WooCommerce orders ( which when using subscriptions is highly probable ) is the comments count. As you probably know the WooCommerce order notes are stored as comments, on average you have at least 2 notes for each order which results in a lot of comments.

You can prevent that count from taking place in the admin using the code below:

if ( is_admin() ) {
    add_filter( 'wp_count_comments', function( $counts, $post_id ) {
        if ( $post_id )
            return $counts;
        return (object) array(
            'approved'        => 0,
            'spam'            => 0,
            'trash'           => 0,
            'total_comments'  => 0,
            'moderated'       => 0,
            'post-trashed'    => 0,
    }, 10, 2 );
// If running WooCommerce, remove their filter so that nothing funky goes down
remove_filter( 'wp_count_comments', array( 'WC_Comments', 'wp_count_comments' ), 10 );

Another quick improvement if you have lots of “processing” orders is to remove the count that shows up in the admin menu ( which is being called on every screen obviously ).

// Remove order count from admin menu
add_filter( 'woocommerce_include_processing_order_count_in_menu', '__return_false' );