wc-api-custom-meta icon indicating copy to clipboard operation
wc-api-custom-meta copied to clipboard

REST POST with “custom_meta” does not change the field values.

Open ilk2010 opened this issue 9 years ago • 5 comments

`Hi Jason,

Thank you for your wc-api-custom-meta plugin on https://github.com/judgej/wc-api-custom-meta.

I have been trying to use it with woocommerce REST api v3 , but also want to update protected meta fields (the ones starting with “_”) after unprotecting them. But it seems that REST POST with “custom_meta” does not work changing the fields.

I have also tried the approach http://torquemag.io/2015/07/working-with-post-meta-data-using-the-wordpress-rest-api/ But my skills set doesn’t seem to be sufficient to adapt to woocommerce api v3.

Would you know what I could still be doing wrong ?

Thanks for any help ! And have a great day!

IL

Ps: my JSON on the POST looks somewhat like this:

{
                "product": {
                               "title": "42_this_must_work",
                               "id": 39,
                               "created_at": "2016-03-03T14:02:24Z",
                               "updated_at": "2016-03-03T14:02:24Z",
                …
                               "variations": [],
                               "parent": [],
                               "grouped_products": [],
                               "menu_order": 0,
                               "custom_meta": {
                                               "_auction_dates_from": "2016-03-03 00:02",
                                               "_auction_dates_to": "2016-03-03 18:00",
                                               "_auction_relist_fail_time": "",
                                               "_auction_relist_not_paid_time": "",
                                               "_auction_relist_duration": "",
                                               "_et_pb_post_hide_nav": "off",
                                               "_et_pb_page_layout": "et_right_sidebar",
                                               "_et_pb_side_nav": "off",
                                               "_wc_rating_count": [],
                                               "_wc_average_rating": "0"
                               }
                }
}

ilk2010 avatar Mar 04 '16 10:03 ilk2010

Do non-protected custom meta fields get updated? Is is just the protected fields that don't update or are none of the custom fields working on the V3 API?

judgej avatar Mar 04 '16 13:03 judgej

No! No custom_field gets updated, I am afraid! (tried with "pageview", wc "on_sale", shipping_required, )

While title and I guess core Post(<-db) fields do get updated.

Endpoint: https://my.domain.com/wc-api/v3/products

I am especially after the fields: "_auction_dates_from": "2016-03-03 00:02", "_auction_dates_to": "2016-03-03 18:00",

unprotecting is done rude in: meta.php function is_protected_meta( $meta_key, $meta_type = null ) { $protected = (( '_' == $meta_key[0]) && ( strpos($meta_key, '_auction') !== 0));

ilk2010 avatar Mar 06 '16 20:03 ilk2010

Thank you. That detail helps me narrow down what I am looking for.

judgej avatar Mar 06 '16 22:03 judgej

Hi again, got a step closer! Your plugin-works fine including updateing "_" protected fields, if I deactivate all other plugins. I'll now figure out which plugin breaks the request, step by step!

ilk2010 avatar Mar 07 '16 17:03 ilk2010

Use the new v2 REST API (WC 3.x) instead of this plugin. It now does everything this plugin does out of the box. The README gives some examples of how you would manage the metadata fields.

judgej avatar Aug 02 '17 15:08 judgej