Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter hzbn

    (@hzbn)

    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 1 year, 11 months ago by hzbn.
    Thread Starter hzbn

    (@hzbn)

    can I have a personalized code? to add it myself in the form because I really need this function in the wcfm form or some other trick for the customer to register as a wholesale seller and fill in the necessary data to be a seller wcfm at the same time. This function is really necessary for the plugin to work with wcfm. tell me if to retrieve the roles this function is correct: // Retrieve WholesaleX roles
    function get_wholesalex_roles() {
    // Use wholesale_user_roles to retrieve WholesaleX roles
    $roles = wholesaler_user_roles();
    return $roles;
    }
    and whether there is a function of saving role data in Wholesalex.
    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)