Php WC REST API |未上载属性

Php WC REST API |未上载属性,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我有一个名为“颜色”的属性,它有两个属性“红色”和“绿色”。 当我使用WC REST API运行它时 一切都是从下面的代码工作,我坚持与属性 print_r( $client->products->create( array( 'title' => 'Nile - Over Counter Basin', 'sku' => '91081_Nile', 'type' => 'simple', 'regular_price' =&g

我有一个名为“颜色”的属性,它有两个属性“红色”和“绿色”。
当我使用WC REST API运行它时

一切都是从下面的代码工作,我坚持与属性

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>',
'attributes' => Array ('name'=>'Color','slug'=>'color','position'=>'0','visible'=>'true','options'=>'Red'),
    'enable_html_short_description' => true,  // This is the line you need to add 
)  ) ) ;

您需要将属性作为数组的数组传递,更改

'attributes' => Array ('name'=>'Color','slug'=>'color','position'=>'0','visible'=>'true','options'=>'Red'),

附言:我假设分类法和术语已经存在,并且分类法的类型设置为文本

编辑


当分类法的类型设置为“文本”时,以纯文本形式传递
options

'options' => 'term'

当分类法的类型设置为“选择”时,作为数组传递
options

'options' => array( 'red', 'white' )
要传递多个属性,请将它们作为数组数组发送,例如:

'attributes'=>array(
    array( 'name'=>'Color', 'slug'=>'color', 'position'=>'0', 'visib‌​le'=>true, 'options'=> array('Starwhite') ),
    array( 'name'=>'Washbasin Type', 'slug'=>'washbasin-type', 'position'=>'0', 'visible'=>true, 'options'=> array(‌​'Washbasin With Pedestal') ),
);

再次感谢你,这很有效。许多人建议更改API版本。。但这解决了我的问题。如果我对同一产品有多个属性,我将如何修改您的解决方案?它们是否属于多个数组?还是单阵列?你能给我举个例子吗?多属性:(颜色:白色,红色)(型号:壁挂式)(坦克:陶瓷)您需要传递多个数组元素,例如
'Attributes'=>array(array('name'=>'Color'..),array('name'=>'Model'..)
属性被视为纯文本,与真实属性不同。示例我附上了上面问题中的图片。底座式洗脸盆显示为纯文本,但应显示为与桌面式洗脸盆相同的真实属性。。如果我错了,你能建议一下吗..当分类法的类型设置为“选择”时,你需要将选项作为数组传递,
'options'=>array('Red')
'options' => array( 'red', 'white' )
'attributes'=>array(
    array( 'name'=>'Color', 'slug'=>'color', 'position'=>'0', 'visib‌​le'=>true, 'options'=> array('Starwhite') ),
    array( 'name'=>'Washbasin Type', 'slug'=>'washbasin-type', 'position'=>'0', 'visible'=>true, 'options'=> array(‌​'Washbasin With Pedestal') ),
);