Description
Describe the bug
Hello,
I encountered an issue while developing my latest project. The frontend is hosted at example.com
, while the backend is at api.example.com
. Due to the different domains, the browser automatically sends an OPTIONS request for CORS.
Since this is done automatically by the browser, we are unable to set the woocommerce-session header. As a result, a new session is created in the wp_woocommerce_sessions table for each OPTIONS request.
To prevent this issue, I believe it would be better to check if the request method is not OPTIONS
before creating a session.
The image below illustrates the unnecessary tokens that are being created.
To Reproduce
Simply call services from a localhost to any backend multiple times. Even though we set the woocommerce-session header, there is nothing we can do for the OPTIONS
requests.
If you agree, I can implement the necessary changes myself and submit a pull request.
Thank you!