PHP Code to Get List of Users Subscriptions and Subscription Status
-
Hi,
I’m trying to get a comma-delimited string of plan ids for the current user, and also the status of a users subscription for a given plan id…
Here’s the code I’ve got…
Usage:
$plan_ids = get_user_subscriptions_details( ‘plans’ );
or
$plan_ids = get_user_subscriptions_details( ‘status’, ‘1234’ );function get_user_subscriptions_details( $detail_type = null, $plan_id = null ) {
$user_id = get_current_user_id();
$subscriptions = pms_get_member_subscriptions( array( ‘user_id’ => $user_id ) );
$subscription_statuses = pms_get_member_subscription_statuses();$ret_value = ”;
foreach( $subscriptions as $subscription ) {
if ( is_null( $subscription ) )
continue;if ($detail_type === ‘plans’) {
// get a comma separated list of all plans the user is subscribed to
$ret_value .= $subscription->subscription_plan_id . ‘,’;
}
elseif ($detail_type === ‘status’) {
// get the subscription status of the current user
$ret_value = ‘unknown’;
if ($subscription->subscription_plan_id === $plan_id) {
if (!empty( $subscription_statuses[$subscription->status] )) {
$ret_value = $subscription_statuses[$subscription->status];
break;
}
}
}
}
return $ret_value;
}`It’s bypassing the foreach loop altogether, so the pms_get_member_subscriptions() is not returning required info.
Any ideas? Thanks in advance
- The topic ‘PHP Code to Get List of Users Subscriptions and Subscription Status’ is closed to new replies.