wp-graphql-woocommerce icon indicating copy to clipboard operation
wp-graphql-woocommerce copied to clipboard

Unable to view order as a guest

Open sdegetaus opened this issue 8 months ago • 1 comments

Describe the bug I believe there is a logic flaw in the WC_Order Root Query when trying to access an order as a guest. The suspect line is this one.

To my knowledge and according to the docs, the function get_current_user_id() will always return 0 when not logged in, making viewing an order as a guest impossible.

I am new to this plugin, so I may be missing some knowledge. However, since I am taking this theme (WooNuxt) as a starting point and since it is also failing to allow me to see my order as a guest, I believe this might be a bug:

Image

To Reproduce Steps to reproduce the behavior:

  1. Go to WooNuxt
  2. Add a product to your cart
  3. Checkout (as a guest)
  4. You will be redirected to the thankyou page, but you will encounter the aforementioned error message: Not authorized to access this order.

Expected behavior I am expecting to be able to see an order as a guest right after I place one.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Brave
  • Version: 1.77.97 Chromium: 135.0.7049.84 (Official Build) (64-bit)

Plugin Versions

  • WooGraphQL Version: 0.21.0
  • WPGraphQL Version: 2.1.1
  • WordPress Version: 6.8
  • WooCommerce Version: 9.8.1

Let me know if I am missing something 🙂

sdegetaus avatar Apr 17 '25 11:04 sdegetaus

Use customer.orders by including the following in a query with the session token provided in the headers

query {
  customer {
    orders {
      nodes {
        ...order fields
      }
    }
  }
}

Make sure the billing address is set on the user using the updateCustomer mutation.

To learn more see the docs here

kidunot89 avatar Jun 20 '25 15:06 kidunot89