How to Add Wholesale Role Selection to The Wholesale Registration Form

Table Of Contents

    Our WooCommerce Wholesale Prices Premium plugin has a feature to create multiple wholesale customer roles. You can define the wholesale prices, restrict shipping methods, and restrict payment gateway for each role.

    By default, our Wholesale Registration Form will grant your potential wholesale customer role to a selected default user role of your choice. You can find it in WooCommerce > Settings > Wholesale Lead > General > New Lead Role.

    If you’d like your potential wholesale customer to select their own wholesale customer role, you can use the following snippet. Please add it to your child theme’s function.php:

    function my_wwlc_auto_select_role ($user) {
        //get the selected role
        $selected_role = get_user_meta($user->ID, 'wwlc_cf_select_role', true);
        $defaultRole = get_option( 'wwlc_general_new_lead_role' );
        if ($selected_role) {
            $user->remove_role( $defaultRole );
            $user->add_role( $selected_role );
        }
    }
    add_action( 'wwlc_action_after_approve_user', 'my_wwlc_auto_select_role' );

    You’d need to create a custom field for Wholesale Customer role selection first. In this sample, the custom field ID is wwlc_cf_select_role and for each value for the option is the meta key for that user role. eg: wholesale_vip.

    Wholesale Role Selection Sample Setup
    in StylingWooCommerce Wholesale Lead Capture