WooCommerce-REST-API-Client-Library icon indicating copy to clipboard operation
WooCommerce-REST-API-Client-Library copied to clipboard

Product creation with custom field (postmeta)

Open david-vde opened this issue 9 years ago • 2 comments

Hello

I'm trying to insert new products via your library. I got a solution to retrieve products with custom fields by using the following syntax;

$wooCommerceApiClient->products->get(116, array('filter[meta]' => 'true'));

And it works.

But now I'm trying to create new products and set custom fields with your client, but I found no documentation about that, and I'm lost.

have you an idea about how to do that?

I tried something like this:

$wooCommerceApiClient->products->create(array( 'title' => 'Test Product', 'type' => 'simple', 'regular_price' => '9.99', 'description' => 'test', 'reference' => '12345678', 'product_meta' => array( 'reference' => '12345678' ) ));

But it does not works...

Thanks for your help

david-vde avatar Jan 11 '16 11:01 david-vde

Hi! Before I knew that I could (and should) use a filter to get meta data I was using this plugin https://github.com/judgej/wc-api-custom-meta to make transparent use of the WC API with custom meta fields included in the get, set and update operations of product meta data. Now we know that with 'filter[meta]' => 'true' we can get products with meta data, but I don't know how to add or update metadata the way you intend (the same way I've been doing it with the plugin I mentioned), so my bet is still using that little plugin while I solve the add/update thing. Maybe the developers here could help clear the air, or consider implementing some functionality like this if it isn't already done.

Cheers

pipegris avatar Jan 24 '16 15:01 pipegris

Hi, pipegris.

I gived up and made my script with natives wordpress/woo-commerce methods to solve my problem

Thank you anyway

david-vde avatar Jan 24 '16 22:01 david-vde