Skip to content

Commit 01ba622

Browse files
committed
rework how we are potentially saving data, also add in new fields to be saved
1 parent 2810aa8 commit 01ba622

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/AbandonedCheckouts/CheckoutHandler.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,22 @@ 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-
$billing_address = [];
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+
}
217230

218-
foreach( $this->get_billing_address_fields() as $field ) {
219-
$billing_address[ $field ] = WC()->session->get( $field ) ?: WC()->checkout->get_value( $field ) ?: '';
231+
$addresses[ $field ] = $value;
220232
}
221233

222234
if ( empty( $billing_email ) ) {
@@ -277,7 +289,7 @@ protected function save_checkout_data( string $billing_email = '', bool $is_chec
277289
maybe_serialize( [
278290
'products' => array_values( WC()->cart->get_cart() ),
279291
'coupons' => WC()->cart->get_applied_coupons(),
280-
'addresses' => $billing_address,
292+
'addresses' => $addresses,
281293
] ),
282294
$current_time,
283295
strtotime( $current_time ),
@@ -359,7 +371,7 @@ public function delete_expired_checkouts() {
359371
* @author Michael Beckwith <[email protected]>
360372
* @since NEXT
361373
*/
362-
protected function get_billing_address_fields() {
374+
protected function get_the_address_fields() {
363375
return [
364376
'address_1',
365377
'address_2',
@@ -373,6 +385,14 @@ protected function get_billing_address_fields() {
373385
'shipping_country',
374386
'shipping_postcode',
375387
'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',
376396
];
377397
}
378398
}

0 commit comments

Comments
 (0)