Skip to content

Commit 36ee47d

Browse files
authored
Fix ActionScheduler fatal error (#5382)
* Prevent fatals when creating customers via ActionScheduler This seems to have started happening some time between the release of WCPay 4.5.1 and 5.2.1, maybe because of some differences in WooCommerce versions? We're not sure why. Context in p1673303308974939-slack-CGGCLBN58?thread_ts=1673293381.897259&cid=CGGCLBN58
1 parent 71f5db5 commit 36ee47d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fix
3+
4+
Prevent occasional fatal errors when creating customers via ActionScheduler jobs

includes/class-wc-payments-customer-service.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ public function create_customer_for_user( WP_User $user, array $customer_data ):
138138
$this->update_user_customer_id( $user->ID, $customer_id );
139139
}
140140

141-
// Save the customer id in the session for non logged in users to reuse it in payments.
142-
WC()->session->set( self::CUSTOMER_ID_SESSION_KEY, $customer_id );
141+
if ( isset( WC()->session ) ) {
142+
// Save the customer id in the session for non logged in users to reuse it in payments.
143+
WC()->session->set( self::CUSTOMER_ID_SESSION_KEY, $customer_id );
144+
}
143145

144146
return $customer_id;
145147
}

0 commit comments

Comments
 (0)