A Cozmoslabs Product
Documentation / Developer Knowledge Base / Subscription Info Shortcode

Subscription Info Shortcode

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

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
44
45
46
47
48
49
50
51
52
add_shortcode( 'pms-subscription-info', 'pmsc_subscription_info_shortcode' );
function pmsc_subscription_info_shortcode( $atts ){
    $atts = shortcode_atts(	array(
        'id'                => get_current_user_id(),
        'subscription_plan' => '',
        'key'               => '',
    ), $atts );
 
    if (empty($atts['key']) || empty($atts['id']))
        return;
 
    $args = array( 'user_id' => $atts['id'] );
 
    if( !empty( $atts['subscription_plan'] ) )
        $args['subscription_plan_id'] = $atts['subscription_plan'];
 
    $member = pms_get_member_subscriptions( $args );
 
    if ( empty( $member ) )
        return '';
 
    $subscription_plan = pms_get_subscription_plan( $member[0]->subscription_plan_id );
 
    $subscription_statuses = pms_get_member_subscription_statuses();
 
    switch ($atts['key']) {
        case 'start_date':
            return ucfirst( apply_filters( 'pms_match_date_format_to_wp_settings', strtotime( get_date_from_gmt( $member[0]->start_date ) ), false ) );
            break;
        case 'expiration_date':
            return ucfirst( apply_filters( 'pms_match_date_format_to_wp_settings', strtotime( get_date_from_gmt( $member[0]->expiration_date ) ), false ) );
            break;
        case 'next_payment':
            return ucfirst( apply_filters( 'pms_match_date_format_to_wp_settings', strtotime( get_date_from_gmt( $member[0]->billing_next_payment ) ), false ) );
            break;
        case 'status':
            return $subscription_statuses[$member[0]->status];
            break;
        case 'plan_name':
            return $subscription_plan->name;
            break;
        case 'plan_price':
            return $subscription_plan->price;
            break;
        case 'plan_duration':
            return $subscription_plan->duration . ' ' . $subscription_plan->duration_unit;
            break;
        case 'default':
            return;
            break;
    }
}

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket