简体   繁体   English

如果用户有活动订阅,则轻松数字下载(定期付款)显示某些东西

[英]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我只需要向订阅有效的用户展示一些东西,我使用的是 edd 定期付款插件,我发现这是他们的文档

$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.因此,我将在我的 archive.php 文件中添加此代码,并为活跃用户显示额外的 php 代码。

that code you found is part of the OOP class used by Easy Digital Downloads.您找到的代码是 Easy Digital Downloads 使用的 OOP class 的一部分。 Their docs are here: https://docs.easydigitaldownloads.com/article/1160-recurring-payments-developer-eddrecurringsubscriber他们的文档在这里: 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).但请注意,因为如果用户有一个有效的订阅和他/她有一个取消的订阅,该方法将返回 true(但如果订阅已过期,则返回 false)。 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.我没有 EDD,所以没有测试过,但我希望它至少能让你开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM