From ff614f4f99c92cf8a24928bcc5a9383131620502 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 18 Feb 2019 17:25:25 -0300 Subject: [PATCH] Catch WC_Data_Exception to avoid black screen Also incldued a check to avoid duplicated messages about invalid billing address emails. --- includes/class-wc-form-handler.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/includes/class-wc-form-handler.php b/includes/class-wc-form-handler.php index 5f1bc20c35a..a22322ab2d8 100644 --- a/includes/class-wc-form-handler.php +++ b/includes/class-wc-form-handler.php @@ -149,11 +149,18 @@ class WC_Form_Handler { } } - // Set prop in customer object. - if ( is_callable( array( $customer, "set_$key" ) ) ) { - $customer->{"set_$key"}( $value ); - } else { - $customer->update_meta_data( $key, $value ); + try { + // Set prop in customer object. + if ( is_callable( array( $customer, "set_$key" ) ) ) { + $customer->{"set_$key"}( $value ); + } else { + $customer->update_meta_data( $key, $value ); + } + } catch ( WC_Data_Exception $e ) { + // Set notices. Ignore invalid billing email, since is already validated. + if ( 'customer_invalid_billing_email' !== $e->getErrorCode() ) { + wc_add_notice( $e->getMessage(), 'error' ); + } } }