WooCommerce faces a challenge not present on every WordPress site:
It must identify and remember each visitor that interacts with the store, in order to remember their preferences and build a sales order– regardless of whether the user is registered
you could, hypothetically, require every user to register with you WP site
But that would create a lot a “friction” to the purchase with the site.
And WooCommerce needs to do this while maintaining the security necessary for eCommerce sites.
Let’s take a look at how WooCommerce meets these requirements using the WC_Session_Handler throughout each run.
WC()->init()
wc_load_cart()
WC()->initialize_session()
While the WC_Session depends on the cookiewp_woocommerce_session to identify the user, no significant information is stored in that cookie. Instead, the Session assesses if there is new informationaka is the session “dirty” to save, and then updates the database entry accordingly.
Multiple classes use the Session to save customer information, for a seamless of a checkout experience. WC_AJAX often serves as the entry point for processing and forwarding customer information.
Currently the 800lb gorilla governing internet privacy is the European Union’s General Data Protection GuidelinesGDPR, for short. If your site is used by citizens of the EU–regardless of where you or they are in the world–you need to comply with these regulations.
Site Owners must:
These regulations are technology agnostic, so creative implementations of Session Handlers will not circumvent these requirements
add_filter('woocommerce_session_handler', function($handler){
return "My_Awesome_Session_Handler";
});
class My_Awesome_Session_Handler extends WC_Session{
//Do creative and awesome stuff to manage your user sessions here
}
While the default WC_Session_Handler works fine, developers may decide to craft unique customer checkout experiences using custom session handlers. Fortunately, WooCommerce makes this easy with a single filter hook.
Now that you understand how WooCommerce remembers and stores data for each of the site’s customers, you’ll need to consider how WooCommerce combines all of these data points to start building a sale.
To understand that, we need to look at the WC_Cart and its family of classes.
Before moving ahead, take a quick quiz to review.
0 of 3 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 3 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
WooCommerce remembers…
When a session has new information to store in the database, it is considered:
Which class serves as the primary gateway for adding user inputs to the Session?