Last active
January 26, 2017 19:47
-
-
Save tanthammar/0d8ec25a08393ffb6ef70ec341ec7e5e to your computer and use it in GitHub Desktop.
Proposed `custom_user_roles()` function to change `'woocommerce_subscriptions_update_users_role'` default behavior
This file contains hidden or 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 custom_user_roles( $user_id, $role_name ) { | |
$user = new WP_User( $user_id ); | |
//I need help here how to get a meta value from the subscription | |
$subscription_role = ?? | |
$wooSubRole = get_post_meta( $subscription_role, 'wpcf-woo-sub-user-role', true ); | |
// End help needed | |
// Never change an admin's role to avoid locking out admins testing the plugin | |
if ( ! empty( $user->roles ) && in_array( 'administrator', $user->roles ) ) | |
return; | |
// Use subscription post meta value to set active user role | |
if ( $role_name == 'default_subscriber_role'); | |
$role_name = $wooSubRole; | |
else if ( in_array( $role_name, array( 'default_inactive_role', 'default_cancelled_role' ) ) ) | |
$role_name = get_option( WC_Subscriptions_Admin::$option_prefix . '_cancelled_role' ); | |
$user->set_role( $role_name ); | |
do_action( 'woocommerce_subscriptions_updated_users_role', $role_name, $user ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment