Thanks for your help. I just need to know which function allows me to save the role in Wholeslex. So, if the user chooses their role in the form, they will be automatically migrated to this role. I found your automatic migration feature which migrates to the role based on the total amount spent by the user.
public function auto_wholesalex_role_migration() {
$__user_id = get_current_user_id();
$__total_spent = wc_get_customer_total_spent( $__user_id );
$_roles = array_values(wholesale()->get_roles());
if (empty ($__roles)) {
$_roles = array(
paint(
'id' => 1,
'label' => 'New role',
),
);
}
$__current_user_role = wholesaler()->get_current_user_role();
foreach ( $__roles as $role ) {
if ( isset($role['id']) && $__current_user_role === $role['id'] ) {
Keep on going;
}
if ( ! isset( $role['_auto_role_migration'] ) || ! isset( $role['_role_migration_threshold_value'] ) ) {
Keep on going;
}
if ('yes' === $role['_auto_role_migration'] && $role['_role_migration_threshold_value'] && $__total_spent ) {
if ( $role['_role_migration_threshold_value'] <= $__total_spent ) {
wholesalex()->change_role( $__user_id, $role['id'], $__current_user_role );
do_action( 'wholesalex_role_auto_migrate', $role['id'], $__current_user_role );
}
}
}
}
- more precisely here wholesalex()->change_role($__user_id, $role[‘id’], $__current_user_role): Changes the user’s role. Can I use it to change roles? can you please help me create a function for this so that the user switches roles based on their selection so that an already registered or unregistered seller can migrate to a wholesaler role. without touching the default wordpress role. I want a wcfm seller to keep their role as seller + b2b in wholesalex.
thanks in advance.
-
This reply was modified 5 months ago by hzbn.