Limit the WooCommerce Subscriptions to just active or pending-cancel on the My Subscriptions page

I have WooCommerce with Woo Subscriptions. When users go to the My Account → My Subscriptions page they normally see a full list of all of their subscriptions, active or not.

I would like to change that page to only show subscriptions they have which are a status of ‘active’ or ‘pending-cancel’.

My approach is to modify the query before it is run to put a conditional where status == ‘active’ || ‘pending-cancel’.

I’m stuck. I’ve tried different suggested methods of doing this including hooking into ‘pre_get_posts’, ‘posts_where’, ‘query_vars’

Here’s one example of what I’ve tried, and failed, to get working.

add_action('pre_get_posts', 'action_pre_get_posts');
function action_pre_get_posts($query) {
    if ( is_account_page() && isset( $_GET['view-subscription'] ) && $query->is_main_query() ) {
        $query->set( 'post_type', 'shop_subscription' );
        $query->set( 'post_status', array( 'wc-active', 'wc-pending-cancel' ) );
    }
}

Any ideas of how to do this?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.