Skip to content

Instantly share code, notes, and snippets.

@ramiabraham
Last active May 11, 2022 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramiabraham/4f0be110745f0d4e6321ef57964601f2 to your computer and use it in GitHub Desktop.
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).
<?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 );
@rseales
Copy link

rseales commented May 11, 2022

Hi, Ramiabraham, hoy are you? whats is RCP??? is Restrict Content Pro wordpress membership plugin??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment