Skip to content

Instantly share code, notes, and snippets.

@picocodes
Created November 28, 2022 03:18
Show Gist options
  • Save picocodes/8ace1af0dc9e9cf82f1f9985bf7e3800 to your computer and use it in GitHub Desktop.
Save picocodes/8ace1af0dc9e9cf82f1f9985bf7e3800 to your computer and use it in GitHub Desktop.
Update user roles when subscription statuses change
<?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