WooCommerce-REST-API-Client-Library
WooCommerce-REST-API-Client-Library copied to clipboard
Call to a member function update() on a non-object
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