
In a recent Business Bloomer Club Slack thread, a client reported an unusual issue on their WooCommerce store: after making a purchase, some users (around 5-10 per day) find that their sessions or cookies are deleted, leading them to see an error page.
This issue can be incredibly frustrating for both store owners and customers, as it disrupts the user experience and prevents customers from viewing their order confirmation.
Possible Cause of the Issue
The root cause of this problem could be linked to how WooCommerce handles guest checkouts and user sessions. The code in question comes from the class-wc-shortcode-checkout.php
file and includes a check for whether a guest needs to verify their email address. Here’s the relevant section of code:
// For guest orders, request they verify their email address (unless we can identify them via the active user session).
if ( self::guest_should_verify_email( $order, 'order-received' ) ) {
wc_get_template( 'checkout/order-received.php', array( 'order' => false ) );
wc_get_template(
'checkout/form-verify-email.php',
array(
'failed_submission' => ! empty( $_POST['email'] ), // phpcs:ignore WordPress.Security.NonceVerification.Missing
'verify_url' => $order->get_checkout_order_received_url(),
)
);
return;
}
This snippet checks if the customer is a guest and, if so, requests email verification. If the session is not properly maintained, it can lead to situations where users are not recognized correctly during checkout, and they are instead shown an email verification form or an error.
The Workaround
A workaround was suggested on the WordPress.org forums, where users could deactivate the email verification requirement post-purchase. The suggested solution involves using the woocommerce_order_email_verification_required
filter, which would allow store owners to bypass the email verification check:
apply_filters( 'woocommerce_order_email_verification_required', $email_verification_required, $order, $context );
This could potentially resolve the issue by ensuring the session remains intact during the checkout process. For more information on this workaround, you can check out a tutorial I shared on the Business Bloomer blog, which deals with admin-side order page access: WooCommerce: Access Thank You Page from Order Admin.
Additional Troubleshooting Steps
There might also be issues related to session handling, which could explain the inconsistency seen on the first page load. In a recent response, another user mentioned a potential session error that had been experienced when trying to load the cart. A similar issue could be at play here. Here’s a useful article that covers solving cart empty issues, which could also help with session-related problems: WooCommerce: Solving Cart Empty Issue.
Conclusion
To address this issue, itβs important to focus on proper session management and ensure that the userβs session remains intact throughout the checkout process. Using the suggested filter to bypass the email verification step may help, but checking for session-related problems could be another avenue worth exploring.