Remember Client information when returning to checkout in WooCommerce

woo expert

It may not have happened to you but it has happened to your customers many times that, when they reach the checkout page, they have filled in their info, went back to the cart to modify an amount or even to the store to add another product and when they return to the checkout page, some of the info isn’t there anymore, having to complete them again.

checkout billing

That this is the default behavior of WooCommerce, that all visitor data is not saved until the purchase is completed.

Now, is that what you want?

Maybe you prefer to save your customers some time, simply by configuring your site to save all the data at checkout.

The solution is to add this function:

/* Save checkout information */
add_action( 'woocommerce_checkout_update_order_review', 'wphelp_save_checkout_fields', 9999 );
function wphelp_save_checkout_fields( $posted_data ) {
parse_str( $posted_data, $output );
WC()->session->set( 'checkout_data', $output );
return $posted_data;
}
add_filter( 'woocommerce_checkout_get_value', 'wphelp_recover_checkout_fields', 9999, 2 );
function wphelp_recover_checkout_fields( $value, $index ) {
$data = WC()->session->get( 'checkout_data' );
if ( ! $data || empty( $data[$index] ) ) return $value;
return is_bool( $data[$index] ) ? (int) $data[$index] : $data[$index];
}
add_filter( 'woocommerce_ship_to_different_address_checked', 'wphelp_recover_checkout_fields_different_address' );
function wphelp_recover_checkout_fields_different_address( $checked ) {
$data = WC()->session->get( 'checkout_data' );
if ( ! $data || empty( $data['ship_to_different_address'] ) ) return $checked;
return true;
}Code language: PHP (php)
  • The first filter saves the data filled in by the customer when he fills them in during his first visit to the checkout page.
  • The second filter retrieves the data filled in the fields when returning to the checkout page.
  • The third filter does the same but with the data to send to a different address, if any.

All this code must be added according to the instructions in this simple guide:

How useful was this post?

Click on a smiley to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Skip to content