Question

I'm trying to add a bunch of custom fields at the end of the checkout form that collects additional data we'd need to process an order.

This is what I have:

add_action( 'woocommerce_after_order_notes', 'student_info_fields' );

function student_info_fields( $checkout ) {

    echo '<div id="student_info"><span>The following information below will be used to create an account.</span>';

    //This adds a student_name field 
    woocommerce_form_field( 'student_name', array(
        'type'        => 'text',
        'class'       => array('form-row-wide'),
        'label'       => __('Student Name'),
        'placeholder' => __('eg: "John Smith", "Johnny", etc'),
        'required'    => 'true',
    ), $checkout->get_value( 'student_name' ));

    /* I have two other text fields here that follow the same syntax as student_name */

    //This adds a student_gender field 
    woocommerce_form_field( 'student_gender', array(
       'type'        => 'select',
       'label'       => __('Gender', 'woocommerce'),
       'placeholder' => _x('', 'placeholder', 'woocommerce'),
       'required'    => 'true',
       'options'     => array(
          'male' => __('Male', 'woocommerce' ),
          'female' => __('Female', 'woocommerce' )
       ),
    ), $checkout->get_value( 'student_gender' ));

    echo '</div>';

}

The text fields all seem to work, but when I add the student_gender field, my page breaks (all white screen). I'm a little skeeved out by calling the options array within the student_gender array, as well as calling the $checkout ->get_value... line after I declare each field, but I simply don't know what to do.

Any direction you can give me would be so helpful to cracking this nut. Thanks for sticking with it!

Was it helpful?

Solution

I looked at it and figured out what I was screwing up. That is to say, it pointed me toward my label declaration, which I don't think was using the proper syntax.

I changed my code to:

    //This adds a student_gender field 
woocommerce_form_field( 'student_gender', array(
    'type'        => 'select',
    'label'       => __('Student Gender'),
    'placeholder' => _x('', 'placeholder', 'woocommerce'),
    'required'    => 'true',
    'options'     => array(
           'male' => __('Male', 'woocommerce' ),
           'female' => __('Female', 'woocommerce' )
    ),
), $checkout->get_value( 'student_grade' ));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top