Here's code to disable authentication in the WooCommerce REST API. Don't use this on a production site!
Related to last week’s post about WooCommerce REST API authentication, here’s a tiny code snippet to disable authentication in the WooCommerce REST API and so permit all requests. Don’t use this on a production site!
When I was trying to use the WooCommerce REST API to push a ThriveCart order to a WooCommerce site I could not get past the authentication and I gave up, choosing instead to write a standalone script. Later, after posting on the WordPress Ireland Facebook group, I got a suggestion that helped me authenticate correctly.
In my early attempts with the WooCommerce REST API I was tracing through the code using Visual Studio Code and Xdebug. From that I found a filter (‘woocommerce_rest_check_permissions‘) that I was able to use to disable the authentication. This then allowed me to work on the other parts of the order creation.
Don’t use this code
The code is useful if you want to develop the “real” part of some REST API code and don’t want to get bogged down in that pesky authentication stuff. But don’t use this code in a production environment. Or at least add some checks like IP address.