Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Add this to your custom functions.php or to
- * your custom plugin to update the Wordpress role
- * or the member type of the user in BuddyBoss plugin
- * after the user has a cancelled subscription.
- *
- * The subscription must be in cancelled state in this
- * example, but you can adjust the hook accordingly as
- * seen in https://woocommerce.com/document/subscriptions/develop/action-reference/
- */
- // Update Wordpress Role and Profile Type after end of subscription, WooCommerce
- function chrmrtns_remove_role_when_subscription_ends ( $wc_subscription ) {
- $user_id = $wc_subscription->get_user_id();
- $user = $wc_subscription->get_user();
- // if the this is a registered user and this user is not an admin
- if( false != $user && !user_can($user, 'administrator') ){
- // our new role name
- $role = 'subscriber'; // Can be anything like customer, subscriber, whatever
- $profile = 'member'; // Roles need to be set in BuddyBoss Profile Types first, for example member or vip-meber
- //set the new role to our customer
- $user->set_role($role);
- // Set the role in BuddyBoss
- bp_set_member_type($user_id, $profile);
- }
- }
- add_action( 'woocommerce_subscription_status_cancelled', 'chrmrtns_remove_role_when_subscription_ends', 100, 1 );
Advertisement
Comments
-
- https://woocommerce.com/document/subscriptions/develop/action-reference/ will give you other hooks instead, if you want to change role on different events
Add Comment
Please, Sign In to add comment