0

I’ve got a simple php script which is connecting to my wordpress to create a product. Using the woocommerce rest api library.

$woocommerce = new Client(
  'https://dev.example.co.uk',
  '123456789',
  '123456789',
  [
      'wp_api' => true,
      'version' => 'wc/v3',
      'sslverify' => false,
  ]
);

// foreach item

$woocommerce->post( 'products', $data );

Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: cURL Error: SSL certificate problem: self signed certificate in /srv/www/example.co.uk/current/web/app/themes/exampletheme/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php on line 417

I’ve attempted the following: Get the certificate from the dev site:

openssl s_client -connect example.co.uk:443 | tee logfile

Copied the certificate and made a file from it called certificate.crt

MIICyTCCAbGgAwIBAgIJANB2....

Uploaded to:

/srv/www/example.co.uk/current/web/wp/certificate.crt

And now trying to use it to prevent this error. functions.php

add_action( 'http_api_curl', function( $handle ) {
    curl_setopt($handle, CURLOPT_CAINFO, ABSPATH . 'certificate.crt');
});

// the value of ABSPATH is: /srv/www/example.co.uk/current/web/wp/

Same error remains. Can't tell if the custom cert is being used or not too. If it is then something else must be wrong maybe.

  • Do not consider my as an answer but have you tried the option to use Let's Encrypt (letsencrypt.org) instead of a self-signed certificate? – Patrice Poliquin Jun 9 at 13:27
0

@wharfdale I faced the same problem. All you need to do is to open the file vendor\automattic\woocommerce\src\WooCommerce\HttpClient\Options.php and look for function verifySsl() and replace true with false. The line in the function should look like this after change

return isset($this->options['verify_ssl']) ? (bool) $this->options['verify_ssl'] : false;

This option sets curl options for verifying SSL to false in the woocommerece library and it works!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.