From 195acd0866c70cccd9de7a9ccde9a14f8c0fd58f Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Mon, 10 May 2021 14:54:40 -0500 Subject: [PATCH] Skip switch statement if value is empty --- includes/class-wc-checkout.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/includes/class-wc-checkout.php b/includes/class-wc-checkout.php index d750f7e3f0c..31670f6d7f4 100644 --- a/includes/class-wc-checkout.php +++ b/includes/class-wc-checkout.php @@ -696,21 +696,23 @@ class WC_Checkout { $type = sanitize_title( isset( $field['type'] ) ? $field['type'] : 'text' ); - switch ( $type ) { - case 'checkbox': - $value = 1; - break; - case 'multiselect': - $value = implode( ', ', wc_clean( $value ) ); - break; - case 'textarea': - $value = wc_sanitize_textarea( $value ); - break; - case 'password': - break; - default: - $value = wc_clean( $value ); - break; + if ( '' !== $value ) { + switch ( $type ) { + case 'checkbox': + $value = 1; + break; + case 'multiselect': + $value = implode( ', ', wc_clean( $value ) ); + break; + case 'textarea': + $value = wc_sanitize_textarea( $value ); + break; + case 'password': + break; + default: + $value = wc_clean( $value ); + break; + } } $data[ $key ] = apply_filters( 'woocommerce_process_checkout_' . $type . '_field', apply_filters( 'woocommerce_process_checkout_field_' . $key, $value ) );