Merge pull request #27023 from HikeMike/add/hidden-form-field

"Hidden" field type added to woocommerce_form_field() #26468
This commit is contained in:
Ron Rennick 2020-08-20 11:48:26 -03:00 committed by GitHub
commit 51afe3207a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -2811,6 +2811,10 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) {
case 'tel':
$field .= '<input type="' . esc_attr( $args['type'] ) . '" class="input-text ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" value="' . esc_attr( $value ) . '" ' . implode( ' ', $custom_attributes ) . ' />';
break;
case 'hidden':
$field .= '<input type="' . esc_attr( $args['type'] ) . '" class="input-hidden ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" value="' . esc_attr( $value ) . '" ' . implode( ' ', $custom_attributes ) . ' />';
break;
case 'select':
$field = '';

View File

@ -178,4 +178,19 @@ class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
$this->assertEquals( $expected_html, $actual_html );
}
public function test_hidden_field() {
$actual_html = woocommerce_form_field('test',
array(
'type' => 'hidden',
'id' => 'test_field',
'input_class' => array( 'test-field' ),
'custom_attributes' => array( 'data-total' => '10' ),
'return' => true
), 'test value');
$expected_html = '<p class="form-row " id="test_field_field" data-priority=""><span class="woocommerce-input-wrapper"><input type="hidden" class="input-hidden test-field" name="test" id="test_field" value="test value" data-total="10" /></span></p>';
$this->assertEquals( $expected_html, $actual_html );
}
}