0

I have a Nextjs app, that uses the Wordpress REST API to fetch the products. I maintain the cart within React, and I would like to display the WooCommerce checkout page inside an iframe.

I made a custom function in php (I'm not so good with php though), that adds the products to the cart from the url parameters. So the iframe's src looks like this:

https://example.com/<wp_installation_url>/checkout?empty_cart=true&add-to-cart=51,51,53

(51, and 53 being the IDs of the products, and they're repeated by the quantity).

This works perfectly until I'm signed in as the WP site's owner. However when I log out (or open a private page), I get this error on the checkout page:

Sorry, your session has expired. Return to shop

How could I resolve this issue? Maybe fetch an api route in wordpress that would give me a new session? I'm very lost on this one...

  • I think you need to add a nonce to the wp request to authenticate it! – Mattia Rasulo May 24 '22 at 17:42
  • @MattiaRasulo Could you elaborate a bit? Should I pass a nonce to the iframe's url somehow? And where should I get a nonce? –  May 24 '22 at 18:10

0 Answers0