Using the official PHP library for the WooCommerce REST API with basic auth

If a WordPress installation is protected via .htaccess basic auth, the requests against the WooCommerce REST API with the PHP library do not work. I did not find the GitHub issue where someone said that CURL could be used to set the login credentials, but with that information, I found a question and the answers on Stack Overflow, that helped me:

$ch = curl_init(); curl_setopt( $ch, CURLOPT_USERPWD, 'user:password' );

I inserted these two lines at the beginning of my script and replaced user and password with the actual login data. With that, the requests against the protected installation worked.

Related posts

Leave a Comment

Your email address will not be published. Required fields are marked *