|
| 1 | +# Product custom fields # |
| 2 | + |
| 3 | +The product custom fields API allows you to view the custom field names that have been recorded. |
| 4 | + |
| 5 | +## Custom fields available parameters ## |
| 6 | + |
| 7 | +| Parameter | Type | Description | |
| 8 | +| ---------- | -------- | ---------------------------------------------------------------------------------------------------------------------------- | |
| 9 | +| `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | |
| 10 | +| `page` | integer | Current page of the collection. Default is `1`. | |
| 11 | +| `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | |
| 12 | +| `search` | string | Limit results to those matching a string. | |
| 13 | +| `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | |
| 14 | + |
| 15 | +## Retrieve product custom field names ## |
| 16 | + |
| 17 | +This API lets you retrieve filtered custom field names. |
| 18 | + |
| 19 | +<div class="api-endpoint"> |
| 20 | + <div class="endpoint-data"> |
| 21 | + <i class="label label-get">GET</i> |
| 22 | + <h6>/wp-json/wc/v3/products/custom-fields/names</h6> |
| 23 | + </div> |
| 24 | +</div> |
| 25 | + |
| 26 | +```shell |
| 27 | +curl https://example.com/wp-json/wc/v3/products/custom-fields/names \ |
| 28 | + -u consumer_key:consumer_secret |
| 29 | +``` |
| 30 | + |
| 31 | +```javascript |
| 32 | +WooCommerce.get("products/custom-fields/names") |
| 33 | + .then((response) => { |
| 34 | + console.log(response.data); |
| 35 | + }) |
| 36 | + .catch((error) => { |
| 37 | + console.log(error.response.data); |
| 38 | + }); |
| 39 | +``` |
| 40 | + |
| 41 | +```php |
| 42 | +<?php print_r($woocommerce->get('products/custom-fields/names')); ?> |
| 43 | +``` |
| 44 | + |
| 45 | +```python |
| 46 | +print(wcapi.get("products/custom-fields/names").json()) |
| 47 | +``` |
| 48 | + |
| 49 | +```ruby |
| 50 | +woocommerce.get("products/custom-fields/names").parsed_response |
| 51 | +``` |
| 52 | + |
| 53 | +> JSON response example: |
| 54 | +
|
| 55 | +```json |
| 56 | +{ |
| 57 | + [ |
| 58 | + "Custom field 1", |
| 59 | + "Custom field 2", |
| 60 | + "Custom field 3", |
| 61 | + "Custom field 4" |
| 62 | + ] |
| 63 | +} |
| 64 | +``` |
0 commit comments