Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QUESTION: Adding item to the cart of a certain session #854

Closed
niklaszulus opened this issue May 13, 2024 · 1 comment
Closed

QUESTION: Adding item to the cart of a certain session #854

niklaszulus opened this issue May 13, 2024 · 1 comment

Comments

@niklaszulus
Copy link

I've been following this guide because i want to make a Shopify like checkout, which means that i use a mutation to create a cart and then use this url to redirect to the checkout which has the predefined items already in it.

The problem that i am facing is that in the above mentioned tutorial i need to write php code on the server which i either package into a plugin or put it in the functions.php.

The guide accomplishes this by letting the frontend make an addToCart mutation and puts the items which have to be available at checkout in it

e.g. making a cart for a checkout with a single product in it
mutation { addToCart(input: {productId: 13}) { cart { total } } }
then save the "woocommerce-session" token out of the response header, decode it (because its a JWT) and then get the session which has the items stored in the cart (due to the cart mutation.
The decoded session is then passed as an url argument e.g. (woocommerce-page.com/checkout/session_id=${sessionId})
Now the woocommerce backend takes this url argument and reconstructs the session (code found in guide).

It seems like this is possible without writing custom php code for the backend since we can create checkoutUrls and transfer the session via transfer-session endpoint.

But how do I put the item which i want to have in the checkout in the cart and not loose the checkoutUrl in the process without going through above mentioned trouble?

@niklaszulus
Copy link
Author

Solved:

I got the checkoutUrl via the updateSession mutation which is also availiable with the addToCart mutation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant