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

Call to a member function update() on a non-object #239

Open MND13 opened 6 years ago

MND13 commented 6 years ago

Hi, i have the same issue as this https://stackoverflow.com/questions/29635202/woocommerce-downloadable-files-disappear-after-database-restore

I have applied the updated code $wc_api->products->update( $product_id, array('title'=>$name,'downloads'=>array(array('name'=>$name,'file'=>$newURL))));

so mine looks like this:

while($row = $result->fetch_assoc()) {

    $product_id = $row["post_id"];
    $meta_value = $row["meta_value"];
    preg_match("/.+\:\"(https:\/\/.+\/wp-content\/uploads\/.+\/.+\/(.+)\..+)\".+/", $meta_value, $m);

    print_r($wc_api->products);

    try {

        print_r( $wc_api->products->update( $product_id, array('title'=>$name,'downloads'=>array(array('name'=>$m[2],'file'=>$m[1])))) );

    } catch ( WC_API_Client_Exception $e ) {
        echo $e->getMessage() . PHP_EOL;
        echo $e->getCode() . PHP_EOL;

        if ( $e instanceof WC_API_Client_HTTP_Exception ) {
            print_r( $e->get_request() );
            print_r( $e->get_response() );
        }
    }

  }

but its causing a Fatal error: Call to a member function update() on a non-object. WC_API_Client_Exception errors are also not visible. I am using the Woocommerce Version 3.2.6 and a recent copy of this API