When working with the API recently I found if the authentication header with the consumer key as the username and the consumer secret as the password is present and valid this sets the current user global as the matched user.
I found the core executes the REST route until current_user_can is called, at which point if the header was missing or invalid the current user ID is 0 and as ‘current user cant’, this prevents the request from further processing.
Looking at your solution, $user need not be defined as it is unused by the WC_API_Authentication::authenticate() method.
If this fixed your code, it would suggest you haven’t registered a REST route (/wp-json/wc/v1/my-route) and have defined a custom handling of the request yourself.
You may wish to look at the ‘woocommerce_api_endpoints’ filter instead.
Related Posts:
- Add Products to user’s ID Woocommerce
- How to save generated JWT token to cookies on login?
- How to modify WCMP Rest API response?
- how to do login using woocommerce rest api From android
- Change Dashboard URL from wp-admin to wp-admin/index.php
- One WooCommerce Store to multi distributor sites
- Getting all woocommerce products from REST API call in plugin
- Fetching users data from REST API
- Social login authentication via wordpress rest api
- WooCommerce REST API aborts connection [closed]
- Limit post creation by role
- Save custom attributes of product in woocommerce
- Filtering WooCommerce Orders by Category
- trying to get product category image in woo-coomerce
- How to add checkboxes for a woocommerce product? [closed]
- Why am I getting ( WooCommerce Services could not be installed (Could not create directory.). ) error and how to solve it ?
- Ajax with plugins returns 0
- Why can’t I access my Intranet LDAPS with NADI?
- Product queue for my subscription box
- Want to Show Sub categories under Categories section using Woo Commerce [closed]
- Set plugin-values when creating post via REST-API
- Can’t view ‘More details’ on plugins pop up is blank and Authy pop up
- Custom Pages for Woocommerce Product-Category Pages
- Woocommerce Minimum Price for a Composite Product to add in cart
- creating a custom shop page display on archive woocommerce
- AFNetworking incorrectly interpreted WP_Error
- Woocommerce Shop page variation product button replace with add to cart button
- How can I insert thousands of Woocommerce products by batch with PHP? [closed]
- WooCommerce search products between price range using WP_Query
- Redirect to another page using contact form 7? [closed]
- Access WP_REST_Server from within plugin namespace
- How to use add_submenu_page() for editors?
- PHP Error When a plugin is active
- woocommerce with custom post type
- Is there a way to get plugins and themes not built for multisite to work on a network subsite?
- JWT on Woocommerce cannot work with “Customer” role user
- Exact Hook to payment methods
- REST route from a plugin not working if WordPress is installed in a subdirectory
- Restrict content based on buy woocommerce product
- Plugin retrieving results even after uninstallation
- How to get a list of bundled products using wp_query in woocommerce
- Getting a Page via its post-name using WP REST API v2 and Postman
- Adding Static Image to WooCommerce Content-Single-Product template
- WordPress REST API Plugin Development – Add Custom Endpoint
- Hide a Menu Item on Login
- Product count in archive page Title in WooCommerce [closed]
- Add item to the woocommerce dashboard menu from a plugin
- How to create WordPress custom end point with multiple parameters?
- WooCommerce – set session with new cart item meta when updating cart item quantity [closed]
- How to get the particular product quantity in orders in Woocommerce [closed]
- How to execute plugin and theme updates from a web hook / endpoint?
- Get Every Key & Value from Array then Display All in New Line
- Woocommerce Coupon Menu and Marketing Menu missing After “Coupons can now be managed from Marketing > Coupons.” [closed]
- Get orders of a specific customer woocommerce
- What am is missing? (API CORS)
- How do I make reusable content blocks for header and footer when using WordPress headless with another front-end?
- WooCommerce: Force coupon for existing/registered customers [closed]
- REST API can’t get the response manually
- Add_rewrite_endpoint doesn’t work with post name permalink structure
- wc_get_template new template does not showing up
- Show icons or badges under title on product archives/category pages
- Conditional Shipping Options if Certain Products are in Cart WooCommerce
- WordPress Stock Update Programatically
- Woocommerce Backend Search by Title and SKU
- How to integrate together a website currently hosted WordPress.com and a custom web application currently hosted on Azure?
- Problem with add_action
- Custom API plugin to execute 3rd party API to retrieve data
- WooCommerce Shopping Cart Not Initially Showing Products [closed]
- How can I concatenate variables to search results title? [closed]
- WooCommerce: after install hook
- How to add a new column with text fields to WooCommerce Cart List?
- Add a “View all” button on WooCommerce product archives pages
- I am trying to make a field show and save from quickedit screen
- Woocommerce: limit user to see only the products he created
- Woocommerce singe product custom gallery output works just on the first slide
- How to include a custom field in the woocommerce email?
- woocommerce search by sku and title ajax
- Woocomerce add info after order email prouct item
- Remove Pagination for Product Category Pages WooCommerce
- add seperate suffix for low price and high price in woocommerce
- Get products list by url key in WordPress Woocommerce [closed]
- Cross Sells are not being shown in Cart Page. Please Help!
- Possibility to login without password
- How to display registered customer list as dropdown in WooCommerce checkout?
- How do I get the Payzone WooCommerce payment gateway plugin to show up in the settings? [closed]
- Error with get_price (and others) in self-written plugin to show price
- How to change WooCommece variation data programmtically [closed]
- Getting a ressource ID, from a WC_Order_Item_Product/Order
- .php file for woocommerce edit category? [closed]
- Woocommerce – WordPress Roles & Capabilities
- Advanced Custom Fields (acf) – Filter Relationship by Taxonomies not Post Type
- Sending customer an email with link to stripe to make payment
- Override a Plugin Function
- Custom template for all woo commerce categories
- How to remove products-links after the product title using remove_action
- Search users with custom meta data
- WordPress Multi-Step Product Search
- Is it possible to instantiate a new WC_Cart?
- Woocommerce Free shipping method [closed]
- how get curent URL slug from archive page [closed]