如何检测用户是否已经订阅了 Memberpress 产品 [英] How can I detect if user has subscribed Memberpress product already

查看:21
本文介绍了如何检测用户是否已经订阅了 Memberpress 产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测用户是否已经购买了会员产品.

How can I detect if user has already bought a memberpress product.

我正在搜索这样的内容:

I'm searching something like this:

if(have_subscription){ 
   //code to add button
}else{
   // code to add something else
}

推荐答案

使用 MemberPress 的内置功能,这应该非常简单:

This should be pretty straight forward using MemberPress' built in capabilities:

if(current_user_can('memberpress_authorized')) {
  // Do authorized only stuff here
}
else {
  // Do unauthorized stuff here
}

MemberPress 还为每个 MemberPress 会员资格添加了功能,因此您也可以执行以下操作:

MemberPress also adds capabilities for each MemberPress Membership so you could also do something like this:

if(current_user_can('memberpress_product_authorized_123')) {
  // Do authorized only stuff here
}
else {
  // Do unauthorized stuff here
}

在第二个例子中,数字 123 是 MemberPress 会员的 ID.

In the second example the number 123 is the id of the MemberPress membership.

这篇关于如何检测用户是否已经订阅了 Memberpress 产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆