How can I detect if user has already bought a memberpress product.
I’m searching something like this:
JavaScript
x
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:
JavaScript
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:
JavaScript
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.