I am using WooCommerce Subscription and I want to count all expired subscriptions then output that in a column of custom plugin's page in WordPress admin panel. This is what I have so far. But it does not work as expected. It always displays 0.
$subscription_expiry_count=0;
foreach ($users as $user_id) {
$users_subscriptions = wcs_get_users_subscriptions($user_id->id);
if ($users_subscriptions->has_status(array('expired'))) {
$subscription_expiry_count= $subscription_expiry_coun+1;
}
}
echo '<div><p>Total Expired Subscriptions</p><p>'.$subscription_expiry_count.'</p>';
There are some mistakes in your code, try the following revisited code instead: