plugins – Map Custom Registration Fields to WordPress User Roles

Question

How do I map these custom fields to the user profile?

Desired Functionality:
if selected Consumer user role should be the ‘Default- WordPress Role
if selected ‘Wholesale Buyer’ user role should be ‘Administrator’

Here’s – What I have so far?

function iconic_get_account_fields() {
    return apply_filters( 'iconic_account_fields', array(
        'user_url' => array(
            'type'        => 'select',
            'label'   => __( 'Select Field', 'iconic' ),
            'options' => array(
                '' => __( 'Select Customer', 'iconic' ),
                1  => __( 'Consumer', 'Consumer' ),
                2  => __( 'Wholesale Buyer', 'Wholesale' ),
            ),
            'required'    => true,
        ),
    ) );
}
/**
 * Add fields to the registration form and account area.
 */
function iconic_print_user_frontend_fields() {
    $fields = iconic_get_account_fields();

    foreach ( $fields as $key => $field_args ) {
        woocommerce_form_field( $key, $field_args );
    }
}

add_action( 'woocommerce_register_form', 'iconic_print_user_frontend_fields', 10 ); // register form
add_action( 'woocommerce_edit_account_form', 'iconic_print_user_frontend_fields', 10 ); // my account

0
Saquib Ahmed 1 month 2021-08-09T20:32:07-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse