Skip to content

Commit 44e50cf

Browse files
committed
Example file for use with composer.
Formatted PSR-2 style rather than WP style, since composer-based apps will not be likely to be running inside WP.
1 parent 4c4cd99 commit 44e50cf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

example/composer-example.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use WC_API_Client;
4+
use WC_API_Client_Exception;
5+
6+
$options = array(
7+
'debug' => true,
8+
'return_as_array' => false,
9+
'validate_url' => false,
10+
'timeout' => 30,
11+
'ssl_verify' => false,
12+
);
13+
14+
try {
15+
$client = new WC_API_Client(
16+
'http://your-store-url.com',
17+
'ck_enter_your_consumer_key',
18+
'cs_enter_your_consumer_secret',
19+
$options
20+
);
21+
22+
// index
23+
//print_r($client->index->get());
24+
25+
// For other endpoints, see example.php
26+
27+
} catch (WC_API_Client_Exception $e) {
28+
echo $e->getMessage() . PHP_EOL;
29+
echo $e->getCode() . PHP_EOL;
30+
31+
if ($e instanceof WC_API_Client_HTTP_Exception) {
32+
print_r($e->get_request());
33+
print_r($e->get_response());
34+
}
35+
}

0 commit comments

Comments
 (0)