1

With the REST API in 4.7, Woocommerce will be deprecating its own API so I'm looking to use the WP API to create products but I couldn't find any examples since its just been released.

Can someone please post a quick example creating a product with the new API?

4

The new api's documentation can be found here Woocommerce Rest API

And you can create a Woocommerce product by posting data to the wp-json endpoint /wp-json/wc/v1/products (Documentation Here)

$data = [
    'name' => 'Premium Quality',
    'type' => 'simple',
    'regular_price' => '21.99',
    'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
    'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
    'categories' => [
        [
            'id' => 9
        ],
        [
            'id' => 14
        ]
    ],
    'images' => [
        [
            'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
            'position' => 0
        ],
        [
            'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg',
            'position' => 1
        ]
    ]
];

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

This uses the NEW REST API based on the WP REST API

The first change is with endpoints, in our current API you can fetch your orders using:

https://your-woo-store.com/wc-api/v3/orders

The new REST API will instead use:

https://your-woo-store.com/wp-json/wc/v1/orders

  • 1
    I do not want to use the WooCoomerce API. Read "What API should I use in my Apps?" here: woocommerce.wordpress.com/2016/04/22/… – Nimbuz Dec 18 '16 at 23:49
  • Yes, this is using the default wordpress REST API not woocommerce API – Tunji Dec 19 '16 at 9:27
  • Actually it is the Woocommerce API using WP API internally. But yes, a viable solution nonetheless. – Nimbuz Dec 24 '16 at 3:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.