Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with creating a new WooCommerce product with ACF fields #402

Open
kamil-homer opened this issue Jun 7, 2022 · 1 comment
Open

Comments

@kamil-homer
Copy link

Hi
I have a NodeJS app to manage my WordPress.
I'm creating a new WooCommerce product with normal POST and it is working fine. Product is added.

fetch(https://my-website/wp-json/wc/v3/products, {
method: 'POST',
headers: {
   'Content-Type': 'application/json',
   Authorization: WOO_API_AUTH_REQUEST
 },
body: JSON.stringify({
   name: "product name",
   regular_price: "420",
   fields: {
      nku: "new nku"
   }
})})

image

However the "acf" values (aka 'fields') are not updated.
image

The sad part is, that it works fine with regular WordPress posts, under endpoint /wp/v2/posts. Post is created and populated with ACF fields
image

I was trying to use PUT on the existing product, but it doesn't update the ACF fields as well.

Options are enabled
image

User in WooCommerce REST API settings has Read/Write access.

Am I missing something or is it a known issue, that we can't update ACF in the WooCommerce product?

WordPress: 6.0
ACF to REST: 3.3.3
ACF: 5.12.2
WooCommerce: Version 6.5.1

@kamil-homer
Copy link
Author

I think the solution is to use meta_data instead

name: "New Product",
regular_price: "420",
fields: {
    nku: "it doesn't work",
    sku: "it doesn't work"
},
meta_data: [
     {
        "key": "nku",
        "value": "5244KA12"
     },
    {
        "key": "sku",
        "value": "123JAKIWU1"
    }
],

image
image

Product is added with populated ACF fields.
'id' in the meta_data is added automatically. Looks like it needs only the key and value.

@airesvsg I let you decide if it is a feature or a bug and if the issue should be close :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant