Customer data not saved in checkout
-
A customer has just complained that the customer data (checkout form) are not saved after changing something on the cart page (user is not logged in). I can reproduce the problem on my staging server with just Storefront installed. While the address is saved in the session, Name, email, telephone etc. are not.
I can easily fix this with this snippet:
add_action( 'woocommerce_checkout_update_order_review', 'custom_preserve_all_checkout_fields_in_session' ); function custom_preserve_all_checkout_fields_in_session( $post_data ) { parse_str( $post_data, $post_array ); $prefixes = array( 'billing_', 'shipping_' ); $fields = array( 'first_name', 'last_name', 'company', 'country', 'address_1', 'address_2', 'postcode', 'city', 'state', 'phone', 'email' ); foreach ( $prefixes as $prefix ) { foreach ( $fields as $field ) { $full_field_key = $prefix . $field; if ( isset( $post_array[ $full_field_key ] ) ) { $method_name = 'set_' . $full_field_key; if ( is_callable( array( WC()->customer, $method_name ) ) ) { $value = sanitize_text_field( $post_array[ $full_field_key ] ); WC()->customer->$method_name( $value ); } } } } }However, what’s the idea behind it? I understand that Woocommerce needs the address for calculating the shipping fee. But this is a major problem in terms of user experience.
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
You must be logged in to reply to this topic.