-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
56 lines (42 loc) · 1.8 KB
/
index.php
File metadata and controls
56 lines (42 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'http://babaplant.com', // your website url here.
'ck_4accfc7######################6842bd42548', // your consumer key.
'cs_7b0f307######################f61344deaa4', // your consumer Secret.
[
'wp_api' => true,
'version' => 'wc/v1',
'query_string_auth' => true,
'verify_ssl' => false,
]
);
use Automattic\WooCommerce\HttpClient\HttpClientException;
try {
// Array of response results.
$results = $woocommerce->get('products');
// Example: ['products' => [[ 'id' => 8, 'created_at' => '2015-05-06T17:43:51Z', 'email' => ...
$json_string = json_encode($results, JSON_PRETTY_PRINT); //1
//here we get disturbed JSON & some of Character are needed to escaped
//we are working on it.stay calm stay connected we will post it earliest.
\print_r($json_string); //2
// all we need is 1 & 2 for JSON print
// Last request data.
$lastRequest = $woocommerce->http->getRequest();
$lastRequest->getUrl(); // Requested URL (string).
$lastRequest->getMethod(); // Request method (string).
$lastRequest->getParameters(); // Request parameters (array).
$lastRequest->getHeaders(); // Request headers (array).
$lastRequest->getBody(); // Request body (JSON).
// Last response data.
$lastResponse = $woocommerce->http->getResponse();
$lastResponse->getCode(); // Response code (int).
$lastResponse->getHeaders(); // Response headers (array).
$lastResponse->getBody(); // Response body (JSON).
} catch (HttpClientException $e) {
$e->getMessage(); // Error message.
$e->getRequest(); // Last request data.
$e->getResponse(); // Last response data.
}
?>