• Resolved hzbn

    (@hzbn)


    hello I want to add the wholesalex role selection in a wcfm form if possible or in any custom form. thanks in advance

    • This topic was modified 5 months ago by hzbn.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Owadud

    (@owadud655)

    Hi there,

    Thanks for reaching out.

    The WholesaleX role selection field currently works only in our form or WooCommerce’s default registration form. It cannot be added to any other forms.

    If needed in another form, we will take it as a request and it might be included in the future.

    Hope to hear from you soon.

    Regards
    Owadud

    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.

    Owadud

    (@owadud655)

    Hi,

    You can try the below code on function.php in your theme.

    function get_wholesalex_roles() {
    if ( function_exists( 'wholesalex' ) && method_exists( wholesalex(), 'get_roles' ) ) {
    $__roles_options = wholesalex()->get_roles( 'roles_option' );
    $transformed_array = array();
    foreach ($__roles_options as $role) {
    $transformed_array[$role['value']] = $role['name'];
    }
    return $transformed_array;
    }
    return array();
    }

    Screenshot for the output: https://prnt.sc/y9V2iCB6v1fJ

    Let me know if this helps.

    Regards
    Owadud

    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 5 months ago by hzbn.

    Hi there,

    I would be glad to inform you that we’ll release a new update for your request regarding the wcfm form.

    Also, would you please spare a moment and share feedback on WordPress? It will motivate us a lot.

    Here is the Link – WholeSaleX

    Thanks in advance.

    • This reply was modified 4 months, 3 weeks ago by Owadud.
    • This reply was modified 4 months, 3 weeks ago by Owadud.
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.