Changing second user role while updating/downgrading membership level - s2member
here is the thing that i want to achive:
s2_member_level0 has the second role "customer" - when upgrading the account via shortcode provided by s2member the account should upgrade to s2member_level1 and change it's second role to "vendor"
and
s2_member_level1 has the second role "vendor" - when downgrading the account via shortcode provided by s2member the account should downgrade itself to s2member_level0 and change it's second role back to "customer"
i'm setting the roles for the different accounts while they are activated with this function in my child theme:
add_action( 'bp_core_activated_user', 'add_secondary_role_new', 10, 1 );
function add_secondary_role_new( $user_id ) {
global $members_template;
$user = get_user_by('id', $user_id);
if (user_can($members_template-member-id,'s2member_level1')){
$user-add_role('vendor');
}
else{
$user-add_role('customer');
}
}
and i want to change the user roles with these function which basically update the userdata in the database:
function change_role_while_upgrade_account(){
global $members_template;
$user = get_user_by('id', $user_id);
$user = wp_update_user(array('ID'=$user,'role'='vendor'));
}
function change_role_while_downgrade_account(){
global $members_template;
$user = get_user_by('id', $user_id);
$user = wp_update_user(array('ID'=$user,'role'='vendor'));
}
So the question is: how can i use this functions (if they are working) with the shortcodes that s2 member generates? Does anyone have a clue and can helpme figure it out?
my shortcodes for upgrading:
[s2Member-PayPal-Button modify="1" level="1" ccaps="" desc="Upgrading Account to Premium" ps="paypal" lc="" cc="EUR" dg="0" ns="1" custom="www.netz-mitteldeutschland.de" ta="0" tp="0" tt="Y" ra="2799.00" rp="1" rt="Y" rr="1" rrt="" rra="1" image="default" output="button" /]
shortcode for unsubscriping:
[s2Member-PayPal-Button cancel="1" image="default" output="anchor" /]
Thanks for your responses
Topic s2member woocommerce-offtopic user-roles Wordpress
Category Web