-1

I'm trying to add custom fields to my WooCommerce checkout scheme (although this could be a situation with custom fields anywhere). I want to add two, but each attempt I've tried to run a function, it only adds the first custom field and not the second. Where in my code does this need to be cleaned up?

function dv_add_checkout_fields( $fields ) {
    $fields['billing_age'] = array(
         'label'        => __( 'Age of the kid(s) you mainly do activities with?' ),
         'type'        => 'select',
         'class'        => array( 'form-row-wide' ),
         'priority'     => 150,
         'required'     => true,
         'options'      => array( '0-2', '3-5', '6-8', '9-12' ),
    );
    array(
         'label'        => __( 'Which part of LA do you live in or are closest to?' ),
         'type'        => 'select',
         'class'        => array( 'form-row-wide' ),
         'priority'     => 150,
         'required'     => true,
         'options'      => array( 'Central LA', 'East LA', 'San Fernando Valley', 'San Gabriel Valley', 'South Bay', 'West LA', 'Orange County' ),
     );
     return $fields;
}
add_filter( 'woocommerce_billing_fields', 'dv_add_checkout_fields' );
Adam Bell
  • 1,049
  • 1
  • 16
  • 50

1 Answers1

0

Actually your array syntax is wrong which return the data $fields.

you are returning $fields and only one array is assigned to that $fields. Another array was not assigned to $fields . Please try below code and compare your code to find the difference.

function dv_add_checkout_fields( $fields ) {
    $fields['billing_age'] = array(
         'label'        => __( 'Age of the kid(s) you mainly do activities with?' ),
         'type'        => 'select',
         'class'        => array( 'form-row-wide' ),
         'priority'     => 150,
         'required'     => true,
         'options'      => array( '0-2', '3-5', '6-8', '9-12' ),
    );
    $fields['living_near'] = array(
         'label'        => __( 'Which part of LA do you live in or are closest to?' ),
         'type'        => 'select',
         'class'        => array( 'form-row-wide' ),
         'priority'     => 150,
         'required'     => true,
         'options'      => array( 'Central LA', 'East LA', 'San Fernando Valley', 'San Gabriel Valley', 'South Bay', 'West LA', 'Orange County' ),
     );
     return $fields;
}
add_filter( 'woocommerce_billing_fields', 'dv_add_checkout_fields' );
Momin IqbalAhmed
  • 950
  • 6
  • 13