Filter
uncanny-automator-pro
wcs_reports_active_statuses
Filters the active statuses displayed in WooCommerce Subscriptions reports.
add_filter( 'wcs_reports_active_statuses', $callback, 10, 1 );
Description
This filter hook allows developers to modify the array of subscription statuses considered "active" for WooCommerce Subscriptions reports. By filtering `wcs_reports_active_statuses`, you can add or remove statuses from the default list, influencing which subscriptions are included in various reporting views. This hook fires when WooCommerce Subscriptions prepares to query for active subscriptions.
Usage
add_filter( 'wcs_reports_active_statuses', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example function to modify the active subscription statuses for reports.
*
* By default, 'on-hold' is commented out, meaning it's not considered an active status.
* This example adds 'on-hold' back into the active statuses, potentially for custom reporting needs.
*
* @param array $statuses The default array of active subscription statuses.
* @return array The modified array of active subscription statuses.
*/
function my_custom_active_subscription_statuses( $statuses ) {
// Add 'on-hold' back into the list of active statuses.
// This could be useful if you want to include subscriptions on hold in your reports.
if ( ! in_array( 'on-hold', $statuses, true ) ) {
$statuses[] = 'on-hold';
}
// You could also remove statuses if needed, for example:
// $statuses = array_diff( $statuses, array( 'pending-cancel' ) );
return $statuses;
}
add_filter( 'wcs_reports_active_statuses', 'my_custom_active_subscription_statuses', 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/woocommerce/helpers/woocommerce-pro-helpers.php:1775
public function evaluate_subscription_product_condition( $product_id, $user_id ) {
$active_statuses = apply_filters(
'wcs_reports_active_statuses',
array(
'active',
'pending-cancel',
/*,'on-hold'*/
)
);
// Check for any Subscription product.
if ( intval( $product_id ) < 0 ) {
$active_subscriptions = wcs_get_users_subscriptions( $user_id );
return ! empty( $active_subscriptions );
}
// Check for Specific Subscription product.
return wcs_user_has_subscription( $user_id, $product_id, $active_statuses );
}