Mike
Mike

Reputation: 199

WooCommerce Subscription - check is subscription active & paid

I am Using WooCommerce Subscribtion Plugin and I want to check is current user has an active and paid subscription on his acccount to put simple if/else in my PHP file like:

if ($subscription = 'active' && is_user_logged_in() )  {
echo "Hello";
} else {
echo "Goodbye";
}

Of course, this code is just a representation of what I want to achieve. How can I do this?

Upvotes: 1

Views: 662

Answers (1)

AspireP
AspireP

Reputation: 42

Assuming you're using the default configuration, anyone that is an active subscriber has the "Subscriber" role - you could use the following;

    $user = wp_get_current_user();
    if ( in_array( 'subscriber', (array) $user->roles ) ) {
        echo "Hello";
    } else {
        echo "Goodbye";
    }

Upvotes: 1

Related Questions