phpwordpresseasy-digital-downloads

Easy Digital Downloads (Recurring Payments) if User Has Active Subscription show Something


I need to show something only to users with active subscriptions, im using the edd recurring payments plugin, I found this is their docs

$subscriber->has_active_subscription()

But im not sure how to make use of it to show something only to users with active subscriptions.

So i will be adding this code in my archive.php file and show extra php code for active users.


Solution

  • that code you found is part of the OOP class used by Easy Digital Downloads. Their docs are here: https://docs.easydigitaldownloads.com/article/1160-recurring-payments-developer-eddrecurringsubscriber

    What you'd need to do is something like:

    $my_user = get_current_user_id(); //grab current user
    
    $subscriber = new EDD_Recurring_Subscriber( $my_user, true ); //pass user id to EDD class
    
    //The EDD class will return its own user object, and on that you can do your check from the question:
    if ($subscriber->has_active_subscription()) {
    echo 'some special message for users with subscriptions';
    } else {
    //do something else
    }
    

    Watch out though, because that method will return true both if user has an active subscription and if he/she has a cancelled subscription (but false if subscription has expired). That may or may not be what you want.

    I don't have EDD so haven't tested this but I hope it at least gets you started.