Skip to content

Instantly share code, notes, and snippets.

@jmarreros
Last active March 28, 2017 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmarreros/3914905709fb0ef5dfd055f51c9a50ca to your computer and use it in GitHub Desktop.
Save jmarreros/3914905709fb0ef5dfd055f51c9a50ca to your computer and use it in GitHub Desktop.
Conexión y Validación de errores para la REST API Woocommerce
<?php
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
use Automattic\WooCommerce\HttpClient\HttpClientException;
try {
$woocommerce = new Client(
'http://tusitio.com/',
'ck_xxx',
'cs_xxx',
[
'wp_api' => true,
'version' => 'wc/v1',
]
);
print_r($woocommerce->get('products'));
} catch (HttpClientException $e) {
\print_r($e);
\print_r($e->getMessage() . PHP_EOL);
\print_r('Code: ' . $e->getResponse()->getCode() . PHP_EOL);
\print_r('Body: ' . $e->getResponse()->getBody() . PHP_EOL);
}
$e->getResponse()->getBody();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment