Skip to content

Commit b0d47d5

Browse files
committed
Tidy-up.
1 parent a852829 commit b0d47d5

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# wc-api-custom-meta
22
WordPress/WooCommerce plugin to support custom meta fields through the product API
33

4-
A very simple plugin that allows you to create, update or remove custom meta fields when
5-
managing prducts through the WooCommerce API.
4+
A very simple plugin that allows you to view, create, update or remove custom meta fields when
5+
managing products through the WooCommerce API v2.
66

77
It is necessary to install this plugin on the WC site providing the API.
8+
89
I have raised a ticket asking whether this can ever be a core feature of WooCommerce,
910
but the ticket has been rejected:
1011

1112
https://github.com/woothemes/woocommerce/issues/7593
1213

1314
It may come back, but this plugin fills a gap in the meantime.
1415

15-
To use it, add elements to the product array passed to the `products` entrypoint. Each element is
16-
an array, with examples that follow:
16+
## Modifying Product Meta
17+
18+
To use it, add elements to the product array passed to the `products` POST entrypoint.
19+
Each element is an array, with examples below. Both `custom_meta` and `remove_custom_meta`
20+
elements are optional.
1721

1822
~~~php
1923
$product = [
@@ -22,6 +26,7 @@ $product = [
2226
...
2327
'custom_meta' => [
2428
'my_custom_field_name' => 'my custom value',
29+
'my_other_custom_field_name' => 'my other custom value',
2530
],
2631
'remove_custom_meta' => [
2732
'remove_all_instances_of_this_field_name',
@@ -32,9 +37,9 @@ $product = [
3237
~~~
3338

3439
That's it. Make sure those elements are in your REST API request, and this plugin is installed at the other end,
35-
and you can set any meta fields you like.
40+
and you can set any meta fields you like, except for the protected fields (see below).
3641

37-
I have not tested this with anything other than strings, so be wary that the behaviour storing other data structures
42+
I have not tested this with anything other than strings, so be aware that the behaviour storing other data structures
3843
in metafields are *undefined* at present.
3944

4045
## Returning Product Meta
@@ -43,17 +48,17 @@ When retrieving a product, the custom product meta fields will be put into the "
4348
retrieving a product through the API. This only works for capability 'manage_woocommerce' to help prevent
4449
leakage of secure data.
4550

46-
The field will look something like this:
47-
48-
"meta": [
51+
The returned `meta` field will look something like this in structure:
4952

50-
{
51-
"test custom field": "Hi There!",
52-
"pv_commission_rate": "",
53-
"ISBN": "1234567890-1"
54-
}
55-
]
53+
~~~json
54+
"meta":
55+
{
56+
"test custom field": "Hi There!",
57+
"pv_commission_rate": "20%",
58+
"ISBN": "978-1910223260"
59+
}
60+
~~~
5661

57-
Both visibla and hidden ("_" prefixed) fields will be included in the list. All raw WooCommerce fields that
62+
Both visible and hidden (with "_" prefixes) fields will be included in the list. All raw WooCommerce fields that
5863
are already present in some form in the product data will be filtered out, leaving only fields added by
5964
third-party plugins or manually by the shop manager.

wc-api-custom-meta.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static function fetchCustomMeta($product_data, $product, $fields, $server
106106
}
107107
unset($value);
108108

109-
$meta = array($all_meta);
109+
$meta = $all_meta;
110110

111111
$product_data['meta'] = $meta;
112112
}

0 commit comments

Comments
 (0)