Use default value only if form was displayed to the user

Also changed variable name for readability
This commit is contained in:
Alfredo Sumaran 2021-05-17 17:15:16 -05:00
parent 32566c508e
commit 79db2d95a0
1 changed files with 2 additions and 2 deletions

View File

@ -685,14 +685,14 @@ class WC_Checkout {
continue;
}
$is_checkout_page = isset( $_REQUEST['woocommerce-process-checkout-nonce'] );
$form_was_shown = isset( $_REQUEST['woocommerce-process-checkout-nonce'] );
foreach ( $fieldset as $key => $field ) {
$type = sanitize_title( isset( $field['type'] ) ? $field['type'] : 'text' );
if ( isset( $_POST[ $key ] ) && '' !== $_POST[ $key ] ) { // phpcs:disable WordPress.Security.NonceVerification.Missing
$value = wp_unslash( $_POST[ $key ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
} elseif ( isset( $field['default'] ) && 'checkbox' !== $type ) {
} elseif ( isset( $field['default'] ) && 'checkbox' !== $type && ! $form_was_shown ) {
$value = $field['default'];
} else {
$value = '';