I am trying to create a woo commerce product using Rest API Provided i have a Consumer Key: and Consumer Secret: With read and Write Authentication am not sure where am going wrong the PHP is not populating any error message nor the Product Was Created.
<?php
require_once 'class-wc-api-client.php';
function addProduct()
{
$options = array(
'debug' => false,
'return_as_array' => false,
'validate_url' => false,
'timeout' => 30,
'ssl_verify' => false,
);
try {
$client = new WC_API_Client( 'http://example.com/demo/workpressistalledlocation/','xxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxx',$options );
$client->products->create( array( 'sku' => '100001', 'title' => 'Superduper product', 'type' => 'simple', 'regular_price' => '21.50', 'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'short_description' => 'Short description for product'));
print_r( $completed_orders );
} 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() );
}
}
}
$completed_ordersthis variable is not initailized..