Update customer with CRUD and set session data at the same time.

Fixes #15965
This commit is contained in:
Mike Jolley 2017-07-05 12:21:46 +01:00
parent 3180f456d2
commit 57ee9f58cf
1 changed files with 15 additions and 2 deletions

View File

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