Subscription Info Shortcode

This shortcode can be used to display information about the current/any users subscription.
Parameters:

  • id – If not set, will default to the currently logged in user
  • key – value that you want to retrieve. Possible keys: start_date, expiration_date, status, plan_name, plan_price, plan_duration

Usage:
[pms-subscription-info key="plan_name"]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
add_shortcode( 'pms-subscription-info', 'pmsc_subscription_info_shortcode' );
function pmsc_subscription_info_shortcode( $atts ){
	$atts = shortcode_atts(	array(
			'id' => get_current_user_id(),
			'key' => ''
		), $atts );
 
	if (empty($atts['key']) || empty($atts['id']))
		return;
 
	$member = pms_get_member_subscriptions(array('user_id' => $atts['id']));
 
	if (empty($member))
		return 'You don\'t have a membership.';
 
	$subscription = pms_get_subscription_plan($member[0]->subscription_plan_id);
 
	$subscription_statuses = pms_get_member_subscription_statuses();
 
	switch ($atts['key']) {
		case 'start_date':
			return ucfirst( date_i18n( 'j F, Y H:i', strtotime( $member[0]->start_date ) ) );
			break;
		case 'expiration_date':
			return ucfirst( date_i18n( 'j F, Y H:i', strtotime( $member[0]->expiration_date ) ) );
			break;
		case 'status':
			return $subscription_statuses[$member[0]->status];
			break;
		case 'plan_name':
			return $subscription->name;
			break;
		case 'plan_price':
			return $subscription->price;
			break;
		case 'plan_duration':
			return $subscription->duration . ' ' . $subscription->duration_unit;
			break;
		case 'default':
			return;
			break;
	}
}