WC REST API | HTML表没有被创建


WC REST API | HTML Table does not get created

WC Rest API将产品上传到wordpress站点。所有的整体都正确上传,但是在简短的描述下,表格没有被创建,只有表格的平面文本以非表格格式显示,只是在woocommerce-api.php中的直线。

代码:

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>')  ) ) ;

答案在第244行wp-content/plugins/woocommerce/includes/api/class-wc-api-product.php

// 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'];
}

第一行代码使用wc_clean清理短描述,然后检查数据中是否传递了enable_html_short_description键,如果设置为true,当满足条件时,它将传递接收到的"非清洁"版本的短描述。

对上面的代码稍加修改就可以得到想要的结果

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 
)  ) ) ;