kloon / WooCommerce-REST-API-Client-Library

A PHP wrapper for the WooCommerce REST API
GNU General Public License v3.0
356 stars 175 forks source link

Custom fields #188

Open dtezcan opened 8 years ago

dtezcan commented 8 years ago

Hi,

I'm trying to update a product with a custom field. Is it possible to do that with this program? and if so how?

current code: `$data = array( 'product' => (object) array( 'managing_stock' => true, 'in_stock' => $inStock, 'stock_quantity' => $aantal, 'regular_price' => (string) $itemresult[$i]->prijs ) );

$woocommerce->products->update($variationid, $data);`

Thanks :)

dyluck07 commented 8 years ago

Hi there! Had the same problem and found the solution. You need to create a API catch handler in your child theme's functions.php. Some saint made this already. Save the class in your child theme folder and include the php class in your functions.php file. The class is here: https://github.com/judgej/wc-api-custom-meta
You then can send them in the same array query from this api client by using syntax below:.
'custom_meta' => array( '_custom_field_A' => 'valuea', '_custom_field_B' => 'valueb')