11# wc-api-custom-meta
22WordPress/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
77It is necessary to install this plugin on the WC site providing the API.
8+
89I have raised a ticket asking whether this can ever be a core feature of WooCommerce,
910but the ticket has been rejected:
1011
1112https://github.com/woothemes/woocommerce/issues/7593
1213
1314It 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
3439That'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
3843in 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 "
4348retrieving a product through the API. This only works for capability 'manage_woocommerce' to help prevent
4449leakage 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
5863are already present in some form in the product data will be filtered out, leaving only fields added by
5964third-party plugins or manually by the shop manager.
0 commit comments