Skip to content

Commit 6d928c3

Browse files
committed
Update example
1 parent 4217d36 commit 6d928c3

File tree

1 file changed

+103
-75
lines changed

1 file changed

+103
-75
lines changed

example/example.php

Lines changed: 103 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,105 @@
11
<?php
22

3-
error_reporting( E_ALL );
4-
ini_set( 'display_errors', 'On' );
5-
require_once "../class-wc-api-client.php";
6-
7-
$consumer_key = 'ck_fcedaba8f0fcb0fb4ae4f1211a75da72'; // Add your own Consumer Key here
8-
$consumer_secret = 'cs_9914968ae9adafd3741c818bf6d704c7'; // Add your own Consumer Secret here
9-
$store_url = 'http://localhost/demo/'; // Add the home URL to the store you want to connect to here
10-
11-
// Initialize the class
12-
$wc_api = new WC_API_Client( $consumer_key, $consumer_secret, $store_url );
13-
14-
// Get Index
15-
//print_r( $wc_api->get_index() );
16-
17-
// Get all orders
18-
//print_r( $wc_api->get_orders( array( 'status' => 'completed' ) ) );
19-
20-
// Get a single order by id
21-
//print_r( $wc_api->get_order( 166 ) );
22-
23-
// Get orders count
24-
//print_r( $wc_api->get_orders_count() );
25-
26-
// Get order notes for a specific order
27-
//print_r( $wc_api->get_order_notes( 166 ) );
28-
29-
// Update order status
30-
//print_r( $wc_api->update_order( 166, $data = array( 'status' => 'failed' ) ) );
31-
32-
// Get all coupons
33-
//print_r( $wc_api->get_coupons() );
34-
35-
// Get coupon by id
36-
//print_r( $wc_api->get_coupon( 173 ) );
37-
38-
// Get coupon by code
39-
//print_r( $wc_api->get_coupon_by_code( 'test coupon' ) );
40-
41-
// Get coupons count
42-
//print_r( $wc_api->get_coupons_count() );
43-
44-
// Get customers
45-
//print_r( $wc_api->get_customers() );
46-
47-
// Get customer by id
48-
//print_r( $wc_api->get_customer( 2 ) );
49-
50-
// Get customer count
51-
//print_r( $wc_api->get_customers_count() );
52-
53-
// Get customer orders
54-
//print_r( $wc_api->get_customer_orders( 2 ) );
55-
56-
// Get all products
57-
//print_r( $wc_api->get_products() );
58-
59-
// Get a single product by id
60-
//print_r( $wc_api->get_product( 167 ) );
61-
62-
// Get products count
63-
//print_r( $wc_api->get_products_count() );
64-
65-
// Get product reviews
66-
//print_r( $wc_api->get_product_reviews( 167 ) );
67-
68-
// Get reports
69-
//print_r( $wc_api->get_reports() );
70-
71-
// Get sales report
72-
//print_r( $wc_api->get_sales_report() );
73-
74-
// Get top sellers report
75-
// print_r( $wc_api->get_top_sellers_report() );
76-
77-
3+
require_once( 'lib/woocommerce-api.php' );
4+
5+
$options = array(
6+
'verbose_mode' => true,
7+
'return_as_array' => false,
8+
'validate_url' => false,
9+
'timeout' => 30,
10+
'ssl_verify' => false,
11+
);
12+
13+
try {
14+
15+
$client = new WC_API_Client( 'http://your-store-url.com', 'ck_enter_your_consumer_key', 'cs_enter_your_consumer_secret', $options );
16+
17+
// coupons
18+
//print_r( $client->coupons->get() );
19+
//print_r( $client->coupons->get( $coupon_id ) );
20+
//print_r( $client->coupons->get_by_code( 'coupon-code' ) );
21+
//print_r( $client->coupons->create( array( 'code' => 'test-coupon', 'type' => 'fixed_cart', 'amount' => 10 ) ) );
22+
//print_r( $client->coupons->update( $coupon_id, array( 'description' => 'new description' ) ) );
23+
//print_r( $client->coupons->delete( $coupon_id ) );
24+
//print_r( $client->coupons->get_count() );
25+
26+
// custom
27+
//$client->custom->setup( 'webhooks', 'webhook' );
28+
//print_r( $client->custom->get( $params ) );
29+
30+
// customers
31+
//print_r( $client->customers->get() );
32+
//print_r( $client->customers->get( $customer_id ) );
33+
//print_r( $client->customers->get_by_email( 'help@woothemes.com' ) );
34+
//print_r( $client->customers->create( array( 'email' => 'woothemes@mailinator.com' ) ) );
35+
//print_r( $client->customers->update( $customer_id, array( 'first_name' => 'John', 'last_name' => 'Galt' ) ) );
36+
//print_r( $client->customers->delete( $customer_id ) );
37+
//print_r( $client->customers->get_count( array( 'filter[limit]' => '-1' ) ) );
38+
//print_r( $client->customers->get_orders( $customer_id ) );
39+
//print_r( $client->customers->get_downloads( $customer_id ) );
40+
//$customer = $client->customers->get( $customer_id );
41+
//$customer->customer->last_name = 'New Last Name';
42+
//print_r( $client->customers->update( $customer_id, (array) $customer ) );
43+
44+
// index
45+
//print_r( $client->index->get() );
46+
47+
// orders
48+
//print_r( $client->orders->get() );
49+
//print_r( $client->orders->get( $order_id ) );
50+
//print_r( $client->orders->update_status( $order_id, 'pending' ) );
51+
52+
// order notes
53+
//print_r( $client->order_notes->get( $order_id ) );
54+
//print_r( $client->order_notes->create( $order_id, array( 'note' => 'Some order note' ) ) );
55+
//print_r( $client->order_notes->update( $order_id, $note_id, array( 'note' => 'An updated order note' ) ) );
56+
//print_r( $client->order_notes->delete( $order_id, $note_id ) );
57+
58+
// order refunds
59+
//print_r( $client->order_refunds->get( $order_id ) );
60+
//print_r( $client->order_refunds->get( $order_id, $refund_id ) );
61+
//print_r( $client->order_refunds->create( $order_id, array( 'amount' => 1.00, 'reason' => 'cancellation' ) ) );
62+
//print_r( $client->order_refunds->update( $order_id, $refund_id, array( 'reason' => 'who knows' ) ) );
63+
//print_r( $client->order_refunds->delete( $order_id, $refund_id ) );
64+
65+
// products
66+
//print_r( $client->products->get() );
67+
//print_r( $client->products->get( $product_id ) );
68+
//print_r( $client->products->get( $variation_id ) );
69+
//print_r( $client->products->get_by_sku( 'a-product-sku' ) );
70+
//print_r( $client->products->create( array( 'title' => 'Test Product', 'type' => 'simple', 'regular_price' => '9.99', 'description' => 'test' ) ) );
71+
//print_r( $client->products->update( $product_id, array( 'title' => 'Yet another test product' ) ) );
72+
//print_r( $client->products->delete( $product_id, true ) );
73+
//print_r( $client->products->get_count() );
74+
//print_r( $client->products->get_count( array( 'type' => 'simple' ) ) );
75+
//print_r( $client->products->get_categories() );
76+
//print_r( $client->products->get_categories( $category_id ) );
77+
78+
// reports
79+
//print_r( $client->reports->get() );
80+
//print_r( $client->reports->get_sales( array( 'filter[date_min]' => '2014-07-01' ) ) );
81+
//print_r( $client->reports->get_top_sellers( array( 'filter[date_min]' => '2014-07-01' ) ) );
82+
83+
// webhooks
84+
//print_r( $client->webhooks->get() );
85+
//print_r( $client->webhooks->create( array( 'topic' => 'coupon.created', 'delivery_url' => 'http://requestb.in/' ) ) );
86+
//print_r( $client->webhooks->update( $webhook_id, array( 'secret' => 'some_secret' ) ) );
87+
//print_r( $client->webhooks->delete( $webhook_id ) );
88+
//print_r( $client->webhooks->get_count() );
89+
//print_r( $client->webhooks->get_deliveries( $webhook_id ) );
90+
//print_r( $client->webhooks->get_delivery( $webhook_id, $delivery_id );
91+
92+
// trigger an error
93+
//print_r( $client->orders->get( 0 ) );
94+
95+
} catch ( WC_API_Client_Exception $e ) {
96+
97+
echo $e->getMessage() . PHP_EOL;
98+
echo $e->getCode() . PHP_EOL;
99+
100+
if ( $e instanceof WC_API_Client_HTTP_Exception ) {
101+
102+
print_r( $e->get_request() );
103+
print_r( $e->get_response() );
104+
}
105+
}

0 commit comments

Comments
 (0)