![](/img/trans.png)
[英]WooCommerce Rest API - adding product author to products list
[英]Adding tags to WooCommerce products through Rest Api
我正在通过以下代码将产品添加到 WooCommerce https://woocommerce.github.io/woocommerce-rest-api-docs/?php#create-a-product
<?php
$data = [
'name' => 'my title',
'type' => 'simple',
'regular_price' => '19',
'description' => 'my description',
'categories' => [
[
'id' => 9
],
],
'tags' => [
[
'name' => 'my tag',
],
],
];
print_r($woocommerce->post('products', $data));
?>
现在我有一些标签是这样的:(标签的数量是可变的,它们在一个数组中)
array (size=3)
'tag1' => string 'tag1' (length=4)
'tag2' => string 'tag2' (length=4)
'tag3' => string 'tag3' (length=4)
我希望在创建产品时将所有这些标签发送到 WooCommerce。 我把数组放在上面的代码中,它得到一个 0 的键,它没有被发送。 有什么解决办法?
也许语法错误? 在这个例子中,我使用的是 id 而不是 slug/name of tags。
<?php
$data = [
'name' => 'my title',
'type' => 'simple',
'regular_price' => '19',
'description' => 'my description',
'categories' => [
[
'id' => 9
],
],
'tags' => [
['id' => 'TAG_ID_int',
],
['id' => 'TAG_ID_int',
],
],
];
print_r($woocommerce->post('products', $data));
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.