Last active
May 11, 2022 04:16
-
-
Save ramiabraham/4f0be110745f0d4e6321ef57964601f2 to your computer and use it in GitHub Desktop.
Add AffiliateWP affiliate when RCP subscription occurs (requires specifying desired RCP action, and subscription).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function rcp_add_affwp_affiliate_at_rcp_sub() { | |
$user_info = get_userdata(); | |
$user_id = $user_info->user_id; | |
$member = new RCP_Member( $user_id ); | |
$subscription_id = $member->get_pending_subscription_id(); | |
if( ! $member || ! $member->ID > 0 ) { | |
die( 'No member found' ); | |
} | |
if( empty( $subscription_id ) ) { | |
$subscription_id = $member->get_subscription_id(); | |
} | |
if( ! $subscription_id ) { | |
die( 'No subscription for member found' ); | |
} | |
if( ! rcp_get_subscription_details( $subscription_id ) ) { | |
die( 'No subscription level found' ); | |
} | |
// check sub id | |
$sub_id_for_affwp = ''; | |
if( $subscription_id === $sub_id_for_affwp ) { | |
// Add as AffiliateWP affiliate | |
affwp_add_affiliate( $data = array( | |
'user_id' => $user_id, | |
'status' => 'pending' | |
) | |
); | |
} else { | |
die( 'Unable to add afffiliate' ); | |
} | |
} | |
// You'll need to specify the desired action in RCP, | |
// as there isn't (that I can tell) a single | |
// action that fires in all cases. | |
// | |
// Another option is to use the RCP method | |
// $member->just_upgraded() | |
// | |
add_action( 'rcp_gateway_something_here', 'rcp_add_affwp_affiliate_at_rcp_sub', 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, Ramiabraham, hoy are you? whats is RCP??? is Restrict Content Pro wordpress membership plugin??