@@ -213,6 +213,24 @@ protected function save_checkout_data( string $billing_email = '', bool $is_chec
213213 $ is_checkout = $ is_checkout ?: is_checkout ();
214214 $ checkout_uuid = WC ()->session ->get ( 'checkout_uuid ' );
215215
216+ $ addresses = [];
217+
218+ foreach ( $ this ->get_the_address_fields () as $ field ) {
219+ $ value = '' ;
220+
221+ $ value_session = WC ()->session ->get ( $ field );
222+ if ( ! empty ( $ value_session ) ) {
223+ $ value = $ value_session ;
224+ } else {
225+ $ value_checkout = WC ()->checkout ->get_value ( $ field );
226+ if ( ! empty ( $ value_checkout ) ) {
227+ $ value = $ value_checkout ;
228+ }
229+ }
230+
231+ $ addresses [ $ field ] = $ value ;
232+ }
233+
216234 if ( empty ( $ billing_email ) ) {
217235 return ;
218236 }
@@ -271,6 +289,7 @@ protected function save_checkout_data( string $billing_email = '', bool $is_chec
271289 maybe_serialize ( [
272290 'products ' => array_values ( WC ()->cart ->get_cart () ),
273291 'coupons ' => WC ()->cart ->get_applied_coupons (),
292+ 'addresses ' => $ addresses ,
274293 ] ),
275294 $ current_time ,
276295 strtotime ( $ current_time ),
@@ -345,4 +364,35 @@ public function delete_expired_checkouts() {
345364 )
346365 );
347366 }
367+
368+ /**
369+ * Return array of address fields we want.
370+ *
371+ * @author Michael Beckwith <[email protected] > 372+ * @since NEXT
373+ */
374+ protected function get_the_address_fields () {
375+ return [
376+ 'address_1 ' ,
377+ 'address_2 ' ,
378+ 'city ' ,
379+ 'country ' ,
380+ 'postcode ' ,
381+ 'state ' ,
382+ 'shipping_address_1 ' ,
383+ 'shipping_address_2 ' ,
384+ 'shipping_city ' ,
385+ 'shipping_country ' ,
386+ 'shipping_postcode ' ,
387+ 'shipping_state ' ,
388+ 'billing_address_1 ' ,
389+ 'billing_address_2 ' ,
390+ 'billing_city ' ,
391+ 'billing_country ' ,
392+ 'billing_postcode ' ,
393+ 'billing_state ' ,
394+ 'billing_phone ' ,
395+ 'billing_email ' ,
396+ ];
397+ }
348398}
0 commit comments