• I search a way for add a new registration at checkout or in register in a user-role depending on the answer of a radio button field.

    1) i make a user role “client-nocard” (this is no problem)

    2) At checkout in example after e-mail, i want to have a radio selector with label “card-member”

    if answer is Yes: add to normal woocommerce user-role ( Client)
    if answer is Yes, show a text field, required to fill in

    if answer is No: add this registrant to custom user-role (client-nocard)

    i have no knowledge about something like this…

    is here somebody who can help me out?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Nicola Mustone

    (@nicolamustone)

    Automattic Happiness Engineer

    Hello there,
    I understand that you want to add a new checkout field, and based on the option selected, you want to register the customer with a different role.

    You can add the checkout field using Checkout Field Editor: https://woocommerce.com/products/woocommerce-checkout-field-editor

    Registering them with the customer role though would require custom coding. This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the following places for more development-oriented questions:

    1. WooCommerce Slack Community: https://woocommerce.com/community-slack/
    2. WooCommerce FB group: https://www.facebook.com/groups/advanced.woocommerce/
    Thread Starter Patrick Horemans

    (@winock)

    i have found a big part of the solution, the only part that is missing is the text field.
    if select, show a text field, required to fill in

    
    add_action('admin_init', 'uiwc_new_role');
    
    add_action( 'woocommerce_after_order_notes', 'custom_checkout_field_with_wholesale_option' );
    function custom_checkout_field_with_wholesale_option( $checkout ) {
    
        if( current_user_can( 'wholesale_customer' ) ) return; // exit if it is "wholesale customer"
    
        echo '<div id="wholesale_checkbox_wrap">';
        woocommerce_form_field('wholesale_checkbox', array(
            'type' => 'checkbox',
            'class' => array('input-checkbox'),
            'label' => __('Do you have a Customer Card?'),
            'placeholder' => __('card'),
            'required' => false,
            'value'  => true
        ), '');
        echo '</div>';
    
    }
    
    // Conditionally change customer user role
    add_action( 'woocommerce_checkout_update_order_meta', 'wholesale_option_update_user_meta' );
    function wholesale_option_update_user_meta( $order_id ) {
        if ( isset($_POST['wholesale_checkbox']) ) {
            $user_id = get_post_meta( $order_id, '_customer_user', true ); // Get user ID
            if( $user_id > 0 ){
                $user = new WP_User($user_id);
                $user->remove_role('customer');
                $user->add_role('kundenkarte');
            }
        }
    } 

    Please help

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

The topic ‘User role in checkout fields’ is closed to new replies.