Skip to content

Commit

Permalink
[Experiment] Fix additional address field validation notices (#44615)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Feb 14, 2024
1 parent 5af8854 commit b94c14e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
}
}

// Force empty rows to have a height.
&::after {
content: " ";
display: inline-block;
}

&:hover,
&:focus,
&.is-highlighted,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Significance: patch
Type: update

This is behind a feature flag.
Comment: This is behind a feature flag
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: update

This is behind a feature flag.
23 changes: 15 additions & 8 deletions plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function add_session_meta_keys( $keys ) {
* @return mixed
*/
public function default_sanitize_callback( $value, $field ) {
return wc_clean( $value );
return $value;
}

/**
Expand Down Expand Up @@ -433,13 +433,6 @@ private function process_select_field( $field_data, $options ) {
return false;
}

// Select fields are always required. Log a warning if it's set explicitly as false.
$field_data['required'] = true;
if ( isset( $options['required'] ) && false === $options['required'] ) {
$message = sprintf( 'Registering select fields as optional is not supported. "%s" will be registered as required.', $id );
_doing_it_wrong( 'woocommerce_blocks_register_checkout_field', esc_html( $message ), '8.6.0' );
}

$cleaned_options = array();
$added_values = array();

Expand Down Expand Up @@ -469,6 +462,20 @@ private function process_select_field( $field_data, $options ) {
}

$field_data['options'] = $cleaned_options;

// If the field is not required, inject an empty option at the start.
if ( isset( $field_data['required'] ) && false === $field_data['required'] && ! in_array( '', $added_values, true ) ) {
$field_data['options'] = array_merge(
array(
array(
'value' => '',
'label' => '',
),
),
$field_data['options']
);
}

return $field_data;
}

Expand Down

0 comments on commit b94c14e

Please sign in to comment.