WooCommerce: How to save verification information when a customer leaves, returns?

Is there an easy way or plugin to save the order information entered by the client after he leaves and returns?

This plugin retains “field information for customers when they move back and forth,” however there are quite a few recent bad reviews in it, so I don’t think I will use this for production. Any alternative suggestion?

+7
php checkout wordpress woocommerce cart
source share
2 answers

https://github.com/kugaevsky/jquery-phoenix/ seems like the perfect answer to this problem.

0
source share

---- Update ----

The code below works, but only if the data is sent!

The only possible ways are to detect javascript / jQuery form event in validation fields and Ajax concern:


I found some really interesting code in this thread that uses session transients to store validation data.

 // this function sets the checkout form data as session transients whenever the checkout page validates function set_persitent_checkout ( $a ) { $arr = array(); foreach ( $a as $key => $value ) if ( ! empty($value) ) $arr[$key] = $value; WC()->session->set( 'form_data', $arr ); return $a; } add_action( 'woocommerce_after_checkout_validation', 'set_persitent_checkout' ); // this function hooks into woocommerce_checkout_get_value to substitute standard values with session values if present function get_persistent_checkout ( $value, $index ) { $data = WC()->session->get('form_data'); if ( ! $data || empty($data[$index]) ) return $value; return is_bool($data[$index]) ? (int) $data[$index] : $data[$index]; } add_filter( 'woocommerce_checkout_get_value', 'get_persistent_checkout', 10, 2 ); // This is a fix for the ship_to_different_address field which gets it value differently if there is no POST data on the checkout function get_persitent_ship_to_different ( $value ) { $data = WC()->session->get('form_data'); if ( ! $data || empty($data['ship_to_different_address']) ) return $value; return is_bool($data['ship_to_different_address']) ? (int) $data['ship_to_different_address'] : $data['ship_to_different_address']; } add_action( 'woocommerce_ship_to_different_address_checked', 'get_persitent_ship_to_different' ); 

Add this code to the functions.php file located in your active child theme or theme.

Author's explanation:

1. Save the form data:

The first set_persitent_checkout function intercepts woocommerce_after_checkout_validation .

Whenever this hook is triggered, any current form data is saved as a WordPress transient through the WC_Session_Handler class (which was recently updated in version 2.5 to be much more efficient).

2. Check the saved data on reboot:

Then we hook on woocommerce_checkout_get_value with get_persitent_checkout . As the name implies, here we check the transients of the session and return any matches for the current field, if found.

3. Do ship_to_different_address work:

The only difficult field was ship_to_different_address , which gets its value using another method.

To get around this, the last function has been added. This works exactly the same as the previous function, but it hooks in woocommerce_ship_to_different_address_checked .

There you have it. It would be nice if the data was saved after each field update during validation, but the woocommerce_after_checkout_validation hook works enough to capture data at all important points.

+7
source share

All Articles