John Franky
John Franky

Reputation: 1042

WC REST API | HTML Table does not get created

The WC Rest API updloads the product to the wordpress site. All the entires are correctly uploaded, however under short discription, the table does not get created, only the plane text of the table is displayed in non table format, just in straight line in woocommerce-api.php.

Code:

print_r( $client->products->create( array( 'title' => 'Nile - Over Counter Basin','sku' => '91081_Nile', 'type' => 'simple', 'regular_price' => '7260', 'sale_price' => '5445','description' => 'Nile - Over Counter BasinOver Counter BasinHindware Italian CollectionContemporary design with smooth flowing line Space for toiletries', 'dimensions'=>array( 'length' =>'67.5' ,'width' =>'39.5','height'=>'12.5'), 'categories'=>array( ' SANITARYWARE' =>'592',' WASHBASIN' =>'650',' Table Top Wash Basin' =>'508'),'images' =>Array ('91081_Nile'=>Array('src'=>'http://www.somethingsomething.com/images/products/91081/2.jpg','title'=>'91081_Nile','position'=>'0') ),'short_description'=>'Contemporary design with smooth flowing line Space for toiletries <table id="ProductDescriptiontable"><tr><td>Brand</td><td>:</td><td class="thirdcolumn">Hindware</td></tr><tr><td>Product Name</td><td>:</td><td class="thirdcolumn">Nile - Over Counter Basin</td></tr><tr><td>Product Description</td><td>:</td><td class="thirdcolumn">Table Top Wash Basin</td></tr></tr><tr><td>Product Color</td><td>:</td><td class="thirdcolumn">StarwhiteIvory</td></tr></table>')  ) ) ;

Upvotes: 0

Views: 355

Answers (1)

Anand Shah
Anand Shah

Reputation: 14913

The answer lies in wp-content/plugins/woocommerce/includes/api/class-wc-api-product.php on line #244

// Enable short description html tags.
$post_excerpt = isset( $data['short_description'] ) ? wc_clean( $data['short_description'] ) : '';
if ( $post_excerpt && isset( $data['enable_html_short_description'] ) && true === $data['enable_html_short_description'] ) {
    $post_excerpt = $data['short_description'];
}

That piece of code in the first line cleans the short description using wc_clean, it then check to see if enable_html_short_description key was passed in the data and if that was set to true, when the condition is met it will pass the "non-clean" version of short description as was received.

A slight change to your code above will get you the desired result

print_r( $client->products->create( array( 
    'title' => 'Nile - Over Counter Basin',
    'sku' => '91081_Nile', 
    'type' => 'simple', 
    'regular_price' => '7260',
    'sale_price' => '5445',
    'description' => 'Nile - Over Counter BasinOver Counter BasinHindware Italian CollectionContemporary design with smooth flowing line Space for toiletries', 
    'dimensions'=>array( 'length' =>'67.5' ,'width' =>'39.5','height'=>'12.5'), 
    'categories'=>array( ' SANITARYWARE' =>'592',' WASHBASIN' =>'650',' Table Top Wash Basin' =>'508'),
    'images' =>Array ('91081_Nile'=>Array('src'=>'http://www.somethingsomething.com/images/products/91081/2.jpg','title'=>'91081_Nile','position'=>'0') ),
    'short_description'=>'Contemporary design with smooth flowing line Space for toiletries <table id="ProductDescriptiontable"><tr><td>Brand</td><td>:</td><td class="thirdcolumn">Hindware</td></tr><tr><td>Product Name</td><td>:</td><td class="thirdcolumn">Nile - Over Counter Basin</td></tr><tr><td>Product Description</td><td>:</td><td class="thirdcolumn">Table Top Wash Basin</td></tr></tr><tr><td>Product Color</td><td>:</td><td class="thirdcolumn">StarwhiteIvory</td></tr></table>',
    'enable_html_short_description' => true,  // This is the line you need to add 
)  ) ) ;

Upvotes: 1

Related Questions