diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 55753c4a497..ab72c34c5c9 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -1884,7 +1884,20 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { } // Custom attribute handling - $custom_attributes = array(); + $custom_attributes = array(); + $args['custom_attributes'] = array_filter( (array) $args['custom_attributes'] ); + + if ( $args['maxlength'] ) { + $args['custom_attributes']['maxlength'] = absint( $args['maxlength'] ); + } + + if ( true === $args['autocomplete'] ) { + $args['custom_attributes']['autocomplete'] = 'true'; + } + + if ( true === $args['autofocus'] ) { + $args['custom_attributes']['autofocus'] = 'autofocus'; + } if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) { foreach ( $args['custom_attributes'] as $attribute => $attribute_value ) { @@ -1892,18 +1905,6 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { } } - if ( $args['maxlength'] ) { - $custom_attributes['maxlength'] = absint( $args['maxlength'] ); - } - - if ( true === $args['autocomplete'] ) { - $custom_attributes['autocomplete'] = 'true'; - } - - if ( true === $args['autofocus'] ) { - $custom_attributes['autofocus'] = 'autofocus'; - } - if ( ! empty( $args['validate'] ) ) { foreach ( $args['validate'] as $validate ) { $args['class'][] = 'validate-' . $validate;