The auto-magic nature of going from the catalog to an order keeps most store owners from thinking too hard about sessions, carts, checkout forms, etc.
…until they decide to create a unique checkout experience for their customers—then advanced WooCommerce developers need to get into the code to fine-tune the experience.
Let’s take a look behind the curtain…
If you prefer to bypass the lesson, and jump straight to the quiz: click here
The WooCommerce Session remembers the customers’ selections, information and data by linking a database entry to a cookie in the user’s browser
The cart, which is stored in the session, stores selections for a future order and calculates the order’s pricing.
The WC_Checkout singleton object collects additional information and builds an order.
WooCommerce’s core provides an abstract WC_Session class, which can be used to create a custom handler, and a default session handler, which can be overriddenThis allows you to consider unique implementations of the session handler–e.g. Perhaps instead of using a cookie on the customer’s browser it would be better to use the fingerprint or IP address
Two additional classes directly pertain to specific data sets with in the WC session:
A sessionIn it’s default implementation “connects” with the user’s browser using the wp_woocommerce_session cookie
Two additional cookies are set, which are primarily used by the front-end’s refresh_cart_fragmentsWhich is much maligned, for performance reasons. functionality:
WC_Sessions are stored in the woocommerce_sessions table in the database. The fields are fairly straightforward:
|Unique ID int
|Serialized array of all the data associated with the customer’s session
|timestamp of session’s expiration
Conceptually simple, but practically complex, the WC_Cart classes in WooCommerce do a lot of heavy lifting. We’ll dive into the details later.
We’ll take an even deeper dive into each of these components in subsequent topics, then take a look at a couple uses cases for creating a unique browsing and checkout experience for your customers.
Let’s do a quick knowledge check, before moving on to the next topics