From ed37f592bf1c5d3efeb7b79f2392a551b42f648c Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 11 Oct 2016 18:08:02 +0100 Subject: [PATCH] Set custom_attributes earlier --- includes/wc-template-functions.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) 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;