Skip to content

Commit

Permalink
session default value for cart
Browse files Browse the repository at this point in the history
  • Loading branch information
frosso committed Jul 16, 2024
1 parent a2f47bc commit 38610db
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions includes/class-wc-payments-payment-request-session-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,20 @@ public function save_data( $old_session_key = 0 ) {
$this->_dirty = false;
}
}

/**
* Get a session variable.
* Overridden default method, so that the `cart` session data always returns a value, in order to prevent the "saved cart after login" feature to get wrong cart data.
*
* @param string $key Key to get.
* @param mixed $default used if the session variable isn't set.
* @return array|string value of session variable
*/
public function get( $key, $default = null ) {
if ( 'cart' === $key && ! isset( $this->_data['cart'] ) ) {
return [];
}

return parent::get( $key, $default );
}
}

0 comments on commit 38610db

Please sign in to comment.