Skip to content
Advertisement

How can I detect if user has subscribed Memberpress product already

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
}

Advertisement

Answer

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 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
}

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

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement