Skip to content

Preventing Unwanted WooCommerce Sessions from Automatic OPTIONS Requests #908

Open
@pooriaset

Description

@pooriaset

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.

image

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions