사용자가 이미 Memberpress 제품을 구독한 경우 어떻게 탐지할 수 있습니까?
사용자가 이미 멤버프레스 제품을 구매한 경우 어떻게 감지합니까?
다음과 같은 것을 검색하고 있습니다.
if(have_subscription){
//code to add button
}else{
// code to add something else
}
이것은 Member Press'의 내장 기능을 사용하면 매우 간단합니다.
if(current_user_can('memberpress_authorized')) {
// Do authorized only stuff here
}
else {
// Do unauthorized stuff here
}
또한 MemberPress는 각 MemberPress Membership에 다음과 같은 기능을 추가합니다.
if(current_user_can('memberpress_product_authorized_123')) {
// Do authorized only stuff here
}
else {
// Do unauthorized stuff here
}
두 번째 예에서는 숫자 123이 MemberPress 멤버십의 ID입니다.
2015년의 답변은 나에게 효과가 없었지만 검색 결과 1위입니다.나중에 다른 사람들을 위해 여기서 찾아낸 결과를 공유해야겠다고 생각했어요.
또, 「product_authorized」기능은, 유효기간을 확인하지 않고, 구입여부만을 확인했다고 생각합니다.
MemberPress는 활성화, 비활성화 또는 없음 여부를 다음과 같이 판단합니다.
$mepr_user = new MeprUser( $user_id );
if( $mepr_user->is_active() ) {
// Active
}else if($mepr_user->has_expired()) {
// Expired
}else {
// Never a member
}
has_expired()사용자가 다른 트랜잭션에서 활성화되어도 true를 반환할 수 있으므로 그것에만 의존하지 마십시오.
특정 구성원을 확인해야 하는 경우 다음을 사용할 수 있습니다.
$user_id = 123;
$membership_id = 5000;
$mepr_user = new MeprUser( $user_id );
$mepr_user->is_already_subscribed_to( $membership_id ); // true or false
// OR
$mepr_user->is_active_on_membership( $membership_id ); // true or false
is_already_subscribed_to()제품 ID만 허용
is_active_on_membership()는 제품 ID, MeprProduct, MeprTransaction 또는 MeprSubscription 중 하나를 허용합니다.
또한 다음 항목을 사용하여 사용자의 활성 구독을 모두 가져올 수 있습니다.
$mepr_user->active_product_subscriptions( 'ids' ); // return array of ids
WordPress 웹 사이트를 열고 다음을 수행합니다.
- 선택한다.
Plugins > Add New - 를 클릭합니다.
Upload Plugin > Choose file - 를 선택합니다.
MemberPress저장된 파일에서 플러그인 - 클릭
Install Plugin > Activate
이제 찾으실 수 있습니다.MemberPressWordPress 대시보드에 추가되었습니다.
이게 도움이 될 거야
언급URL : https://stackoverflow.com/questions/29744672/how-can-i-detect-if-user-has-subscribed-memberpress-product-already
'programing' 카테고리의 다른 글
| 연락처 폼7을 사용하여 POST 데이터를 캡처하는 방법 (0) | 2023.03.20 |
|---|---|
| posts_search의 커스텀 (0) | 2023.03.20 |
| AngularJS: 서버측 검증과의 통합 (0) | 2023.03.20 |
| 응답으로 버튼을 클릭할 때 새 탭에서 페이지를 여는 방법나도 그 페이지로 데이터를 보내고 싶다. (0) | 2023.03.20 |
| 페이지 새로 고침 없이 양식 제출 (0) | 2023.03.20 |