From 57ee9f58cfbacbb4e192f65fc1fe7a736113a825 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 5 Jul 2017 12:21:46 +0100 Subject: [PATCH] Update customer with CRUD and set session data at the same time. Fixes #15965 --- includes/class-wc-form-handler.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-form-handler.php b/includes/class-wc-form-handler.php index c555f6b9495..616676a5178 100644 --- a/includes/class-wc-form-handler.php +++ b/includes/class-wc-form-handler.php @@ -140,8 +140,21 @@ class WC_Form_Handler { if ( 0 === wc_notice_count( 'error' ) ) { - foreach ( $address as $key => $field ) { - update_user_meta( $user_id, $key, $_POST[ $key ] ); + $customer = new WC_Customer( $user_id ); + + if ( $customer ) { + foreach ( $address as $key => $field ) { + if ( is_callable( array( $customer, "set_$key" ) ) ) { + $customer->{"set_$key"}( wc_clean( $_POST[ $key ] ) ); + } else { + $customer->update_meta_data( $key, wc_clean( $_POST[ $key ] ) ); + } + + if ( WC()->customer && is_callable( array( WC()->customer, "set_$key" ) ) ) { + WC()->customer->{"set_$key"}( wc_clean( $_POST[ $key ] ) ); + } + } + $customer->save(); } wc_add_notice( __( 'Address changed successfully.', 'woocommerce' ) );