doupafu6980 2015-09-05 11:55
浏览 30
已采纳

WC REST API | HTML表格未创建

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>')  ) ) ;
  • 写回答

1条回答 默认 最新

  • duanpiyao2734 2015-09-05 14:05
    关注

    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 
    )  ) ) ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行