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

Variations not working #234

Open bedoya opened 6 years ago

bedoya commented 6 years ago

Maybe this library is a little too old, but I was looking for one exactly like this. Sadly it does not have support for variations. I tried creating the method to create a variation, adding the following code to the /lib/woocommerce-api/resources/class-wc-api-client-resource-products.php

public function create_variation( $id, $data ) {
    $this->set_request_args( array(
        'method' => 'POST',
        'body'   => $data,
        'path'   => $id . '/variations',
    ) );
    return $this->do_request();
}

I made sure the product with ID $id exists, but I keep getting a message about the URL is not working, the localhost URL is:

POST: http://localhost/wordpress/wc-api/v2/products/$id/variations