Skip Navigation

[Resolved] I cannot write to custom fields using the WooCommerce REST API (v3)

This support ticket is created 5 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 6.67 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by georgeF-2 5 years ago.

Assisted by: Nigel.

Author
Posts
#1389115

I am trying to:

I have a custom field set up in WooCommerce products (wps_item_id) and when I request product info, the field shows up. However, if I try to write to the field, there is no change.

Example:
$data = [
'toolset-meta' => [
'product-custom-fields' => [
'wps_item_id' => [
'raw' => 'asdasfasdf'
]
]
]

];

$woocommerce->post('products/74251', $data);

The above code will write to any native WooCommerce field, but I cannot get it to write to wps_item_id['raw']

Woocommerce does not return any errors, it merely discards what it cannot use.

I suspect that while I can read the data using the API, I cannot write back to it as the Toolset mapping is for output only, not for input. I do hope I'm wrong. If there is a way around this, I would greatly appreciate hearing about it.

Thank you.

#1389239

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi George

The Toolset REST API is currently read-only, it doesn't offer write capabilities.

Custom fields created with Toolset Types are "just" ordinary post meta, which is literally true for simple fields stored as strings, although a field such as an image field—which stores the image URL—when output will the a full image tag with sizing etc..

For more complex fields when retrieving data using the Toolset REST API it will provide additional information in the results in a custom toolset_meta property.

But the raw values—as stored in wp_postmeta—are also returned in the standard meta property.

You can both read and write the raw custom field values directly using the native WP REST API, you shouldn't need to use either the Toolset REST API (which doesn't support writing) nor the WC REST API (which may not support unrecognised custom fields, I don't know).

#1391801

My issue is resolved now.

We had been using the WC rest interface without luck, stumbled on the native Toolset one, and missed that it was read only. We're tweaking things here to use the WP api for the remaining custom field writes that we need to be able to do.

Thank you!