Skip to content

Commit 6bae8aa

Browse files
Added PHP examples
1 parent 981ea6f commit 6bae8aa

17 files changed

+1406
-48
lines changed

source/includes/v3/_coupons.md

Lines changed: 93 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ curl -X POST https://example.com/wc-api/v3/coupons \
5050
"coupon": {
5151
"code": "new-coupon",
5252
"type": "percent",
53-
"amount": "10",
53+
"amount": 10,
5454
"individual_use": true,
5555
"product_ids": [],
5656
"exclude_product_ids": [],
@@ -75,7 +75,7 @@ var data = {
7575
coupon: {
7676
code: 'new-coupon',
7777
type: 'percent',
78-
amount: '10',
78+
amount: 10,
7979
individual_use: true,
8080
product_ids: [],
8181
exclude_product_ids: [],
@@ -99,12 +99,41 @@ WooCommerce.post('coupons', data, function(err, data, res) {
9999
});
100100
```
101101

102+
```php
103+
<?php
104+
$data = [
105+
'coupon' => [
106+
'code' => 'new-coupon',
107+
'type' => 'percent',
108+
'amount' => 10,
109+
'individual_use' => true,
110+
'product_ids' => [],
111+
'exclude_product_ids' => [],
112+
'usage_limit' => '',
113+
'usage_limit_per_user' => '',
114+
'limit_usage_to_x_items' => '',
115+
'expiry_date' => '',
116+
'enable_free_shipping' => false,
117+
'product_category_ids' => [],
118+
'exclude_product_category_ids' => [],
119+
'exclude_sale_items' => true,
120+
'minimum_amount' => '100.00',
121+
'maximum_amount' => '0.00',
122+
'customer_emails' => [],
123+
'description' => ''
124+
]
125+
];
126+
127+
print_r($woocommerce->post('coupons', $data));
128+
?>
129+
```
130+
102131
```python
103132
data = {
104133
"coupon": {
105134
"code": "new-coupon",
106135
"type": "percent",
107-
"amount": "10",
136+
"amount": 10,
108137
"individual_use": True,
109138
"product_ids": [],
110139
"exclude_product_ids": [],
@@ -131,7 +160,7 @@ data = {
131160
coupon: {
132161
code: "new-coupon",
133162
type: "percent",
134-
amount: "10",
163+
amount: 10,
135164
individual_use: true,
136165
product_ids: [],
137166
exclude_product_ids: [],
@@ -197,13 +226,6 @@ This API lets you retrieve and view a specific coupon by ID or code.
197226
</div>
198227
</div>
199228

200-
<div class="api-endpoint">
201-
<div class="endpoint-data">
202-
<i class="label label-get">GET</i>
203-
<h6>/wc-api/v3/coupons/code/&lt;code&gt;</h6>
204-
</div>
205-
</div>
206-
207229
```shell
208230
curl https://example.com/wc-api/v3/coupons/529 \
209231
-u consumer_key:consumer_secret
@@ -215,6 +237,10 @@ WooCommerce.get('coupons/529', function(err, data, res) {
215237
});
216238
```
217239

240+
```php
241+
<?php print_r($woocommerce->get('coupons/529')); ?>
242+
```
243+
218244
```python
219245
print(wcapi.get("coupons/529").json())
220246
```
@@ -278,6 +304,10 @@ WooCommerce.get('coupons', function(err, data, res) {
278304
});
279305
```
280306

307+
```php
308+
<?php print_r($woocommerce->get('coupons')); ?>
309+
```
310+
281311
```python
282312
print(wcapi.get("coupons").json())
283313
```
@@ -386,15 +416,15 @@ curl -X PUT https://example.com/wc-api/v3/coupons/529 \
386416
-H "Content-Type: application/json" \
387417
-d '{
388418
"coupon": {
389-
"amount": "5"
419+
"amount": 5
390420
}
391421
}'
392422
```
393423

394424
```javascript
395425
var data = {
396426
coupon: {
397-
amount: '5'
427+
amount: 5
398428
}
399429
};
400430

@@ -403,10 +433,22 @@ WooCommerce.put('coupons/529', data, function(err, data, res) {
403433
});
404434
```
405435

436+
```php
437+
<?php
438+
$data = [
439+
'coupon' => [
440+
'amount' => 5
441+
]
442+
];
443+
444+
print_r($woocommerce->put('coupons/529', $data));
445+
?>
446+
```
447+
406448
```python
407449
data = {
408450
"coupon": {
409-
"amount": "5"
451+
"amount": 5
410452
}
411453
}
412454

@@ -416,7 +458,7 @@ print(wcapi.put("coupons/529", data).json())
416458
```ruby
417459
data = {
418460
coupon: {
419-
amount: "5"
461+
amount: 5
420462
}
421463
}
422464

@@ -470,7 +512,7 @@ To update is necessary to send objects containing IDs and to create new not just
470512
</div>
471513

472514
```shell
473-
curl -X PUT https://example.com/wc-api/v3/coupons/bulk \
515+
curl -X POST https://example.com/wc-api/v3/coupons/bulk \
474516
-u consumer_key:consumer_secret \
475517
-H "Content-Type: application/json" \
476518
-d '{
@@ -509,11 +551,34 @@ var data = {
509551
]
510552
};
511553

512-
WooCommerce.put('coupons/bulk', data, function(err, data, res) {
554+
WooCommerce.post('coupons/bulk', data, function(err, data, res) {
513555
console.log(res);
514556
});
515557
```
516558

559+
```php
560+
<?php
561+
$data = [
562+
'coupons' => [
563+
[
564+
'id' => 529,
565+
'amount' => '15.00'
566+
],
567+
[
568+
'id' => 527,
569+
'minimum_amount' => '55.00'
570+
],
571+
[
572+
'id' => 526,
573+
'amount': '20.00'
574+
]
575+
]
576+
];
577+
578+
print_r($woocommerce->post('coupons/bulk', $data));
579+
?>
580+
```
581+
517582
```python
518583
data = {
519584
"coupons": [
@@ -532,7 +597,7 @@ data = {
532597
]
533598
}
534599

535-
print(wcapi.put("coupons/bulk", data).json())
600+
print(wcapi.post("coupons/bulk", data).json())
536601
```
537602

538603
```ruby
@@ -553,7 +618,7 @@ data = {
553618
]
554619
}
555620

556-
woocommerce.put("coupons/bulk", data).parsed_response
621+
woocommerce.post("coupons/bulk", data).parsed_response
557622
```
558623

559624
> JSON response example:
@@ -661,12 +726,16 @@ WooCommerce.delete('coupons/529/?force=true', function(err, data, res) {
661726
});
662727
```
663728

729+
```php
730+
<?php print_r($woocommerce->delete('coupons/529', ['force' => true])); ?>
731+
```
732+
664733
```python
665734
print(wcapi.delete("coupons/529?force=true").json())
666735
```
667736

668737
```ruby
669-
woocommerce.delete("coupons/529?force=true").parsed_response
738+
woocommerce.delete("coupons/529", force: true).parsed_response
670739
```
671740

672741
> JSON response example:
@@ -707,6 +776,10 @@ WooCommerce.get('coupons/count', function(err, data, res) {
707776
});
708777
```
709778

779+
```php
780+
<?php print_r($woocommerce->get('coupons/count')); ?>
781+
```
782+
710783
```python
711784
print(wcapi.get("coupons/count").json())
712785
```

0 commit comments

Comments
 (0)