Catch WC_Data_Exception to avoid black screen

Also incldued a check to avoid duplicated messages about invalid billing
address emails.
This commit is contained in:
Claudio Sanches 2019-02-18 17:25:25 -03:00
parent c62c1e1d05
commit ff614f4f99
1 changed files with 12 additions and 5 deletions

View File

@ -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' );
}
}
}