Ensure the WC session exists before trying to access it

This commit is contained in:
Daniel Dudzic 2024-11-18 20:01:00 +01:00
parent 216e805615
commit f79fb04846
No known key found for this signature in database
GPG key ID: 31B40D33E3465483

View file

@ -100,16 +100,19 @@ return array(
$currency = $container->get( 'api.shop.currency.getter' ); $currency = $container->get( 'api.shop.currency.getter' );
assert( $currency instanceof CurrencyGetter ); assert( $currency instanceof CurrencyGetter );
$session_id = '';
if ( isset( WC()->session ) && method_exists( WC()->session, 'get_customer_unique_id' ) ) {
$session_id = substr(
md5( WC()->session->get_customer_unique_id() ),
0,
16
);
}
return array( return array(
'enabled' => defined( 'WP_DEBUG' ) && WP_DEBUG, 'enabled' => defined( 'WP_DEBUG' ) && WP_DEBUG,
'client_id' => ( $settings->has( 'client_id' ) ? $settings->get( 'client_id' ) : null ), 'client_id' => ( $settings->has( 'client_id' ) ? $settings->get( 'client_id' ) : null ),
'session_id' => substr( 'session_id' => $session_id,
method_exists( WC()->session, 'get_customer_unique_id' ) ?
md5( WC()->session->get_customer_unique_id() ) :
'',
0,
16
),
'amount' => array( 'amount' => array(
'currency_code' => $currency->get(), 'currency_code' => $currency->get(),
), ),