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]
- Hide prices and checkout functionality in woocommerce
- WooCommerce ‘all’ orders no longer being displayed – how may I debug/fix [closed]
- Updating WooCommerce variable product stock issue
- WordPress pods io – Rest API for fetching fields information for custom post type
- How to save Clicks of a download link button while it doesn’t matter if we refresh the page or again login/logout
- WooCommerce Dynamic Cart Pricing
- Add CSS class to add-to-cart button, Woocommerce [closed]
- Remove action from woocommerce barcode plugin [closed]
- Accessing plugin functionality within WP REST API
- Override core woocommerce class
- WooCommerce – Where is functions.php?
- XML sitemap over product variations
- How to remove the woocommerce_checkout_process action hook in woocommerce if particular project in cart [closed]
- wp_authenticate but not logged in
- How can I display a contact form for out of stock products in WooCommerce?
- HTML in WooCommerce settings
- Override Javascript in a Plugin?
- WooCommerce Custom Product to checkout
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- How to enable specific plugin only based around shop manager role?
- how to oauth1 Wp plug-in revoke/reset.?
- Why required field not working in Country dropdown in WooCommerce –
- How to check current user before all actions and filters?
- WooCommerce: Building a page with user input which is used to query order status and external API and return a result
- I want to disable Cash on delivery based on product tag in woocommerce Checkout Page [closed]
- Is there a way to create custom product templates based on category on WooCommerce?
- WooCommerce specifc variations for specific user role [closed]
- Limit post creation by role
- Why can’t I access my Intranet LDAPS with NADI?
- Redirect to another page using contact form 7? [closed]
- woocommerce with custom post type
- JWT on Woocommerce cannot work with “Customer” role user
- How to get a list of bundled products using wp_query in woocommerce
- How to get the particular product quantity in orders in Woocommerce [closed]
- How to include a custom field in the woocommerce email?
- Custom template for all woo commerce categories
- Is it possible to instantiate a new WC_Cart?
- Sell access to form [closed]
- I want to filter my products with attributes [closed]
- Automatic recurring payment using YITH subscription and Dokan Stripe
- apply_filters(woocommerce_get_item_data, …) Causing errors when adding to cart
- How To Use do_shortcode with WooCommerce One Page Checkout
- How to makes changes on the shop/category/tag pages but not on the product pages in woocommerce?
- Hide fields in woocommerce settings
- Visual composer custom element error
- How to send SMS notification to customer after click on submit?
- Escape commas in REST API
- woocommerce: Customize email with item total count
- Plugin which unlock free gift when you reach some amount in cart
- Save order without sending the invoice / order details woocommerce [closed]
- show wc_add notices on particular page in woo commerce custom plugin development
- Make modification of add_to_cart button specific to single page
- How to get the checkout form data from checkout page when place-order button is clicked
- Product Page loads terribly slow when product gallery images are added
- How to make WooCommerce multiple filter with custom meta fields
- Custom form data not displaying in cart page?
- Custom REST API POST Endpoint Not Working, 404 Error
- best way to handle subscriptions with a licence?
- Is there a request for products plugin for WooCommerce
- woocommerce with external ftp site
- Object of class WP_Error could not be converted to string in /formatting.php
- Only return taxonomies that are linked to a category & product
- WordPress eMails not working
- Add WooCommerce vendor slug to auto-generated SKU
- Custom plugin issue – Notice: Trying to get property of non-object in
- fetch price from different table woocommerce
- Cannot save a custom meta field in quick edit
- how to make settings page for woocommerce plugin?
- redirect to a custom page
- wp rest api (v2) filter not working (404 error – rest_no_route)
- WordPress PHP error getting posts from another wordpress blog
- custom REST endpoint not passing body of POST request to callback
- Change value of Points earned in product data
- Problem with conditional woocommerce custom checkout field
- change product image url in widgets & shop page
- How woo-commerce store Product Data value in DB?
- Not getting result using ajax on wordpress
- Which WordPress version to use for improved plugin compatibility? [closed]
- Change All Login/Signup Links in Plugin
- Move related products after product summary? [closed]
- Trying to disable all notifications except for one on woocommerce checkout page with css [closed]
- Woocommerce disable checkout on specific day
- Translate text for empty product
- Filter custom post type returned from REST api
- How can I make a quotation engine like this website in WooCommerce?
- How to show image caption in Woocommerce gallery
- Update post meta Rest Api
- ShipStation WooCommerce Integration error
- Add Text in Single Product Page On a Specific Category
- How to update a lot of posts on my WP site with additional content?