Created
November 28, 2022 03:18
-
-
Save picocodes/8ace1af0dc9e9cf82f1f9985bf7e3800 to your computer and use it in GitHub Desktop.
Update user roles when subscription statuses change
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 | |
add_action( | |
'getpaid_subscription_status_changed', | |
function( $subscription ) { | |
$user = $subscription->get_customer(); | |
if ( empty( $user ) ) { | |
return; | |
} | |
if ( $subscription->is_active() ) { | |
// Update role. | |
$user->add_role( 'getpaid_subscriber' ); | |
} else { | |
// Update role. | |
$user->remove_role( 'getpaid_subscriber' ); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment