Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress Woocommerce REST API更新产品类别_Wordpress_Woocommerce_Woocommerce Rest Api - Fatal编程技术网

Wordpress Woocommerce REST API更新产品类别

Wordpress Woocommerce REST API更新产品类别,wordpress,woocommerce,woocommerce-rest-api,Wordpress,Woocommerce,Woocommerce Rest Api,我在WoodCommerce 3.3.5中使用Wordpress 4.9.5。当在单独的产品管理系统中更改产品时,我使用更新网站上的产品。该库正在使用RESTAPI的v2 使用下面的代码,我成功地更新了基本的产品数据(标题、描述、sku、价格等),但我无法从未分类中获得要更新的类别。如果网站上还没有产品,则在使用类似代码创建产品时也不会设置类别 $client = new WC_API_Client( $domain, $consumerKey, $consumerSecret, $option

我在WoodCommerce 3.3.5中使用Wordpress 4.9.5。当在单独的产品管理系统中更改产品时,我使用更新网站上的产品。该库正在使用RESTAPI的v2

使用下面的代码,我成功地更新了基本的产品数据(标题、描述、sku、价格等),但我无法从未分类中获得要更新的类别。如果网站上还没有产品,则在使用类似代码创建产品时也不会设置类别

$client = new WC_API_Client( $domain, $consumerKey, $consumerSecret, $options );
$client->products->update( $id, array( 
'sku' => $product->sku,
'title' => $product->title, 
'type' => $product->type, 
'status' => $product->status,
'regular_price' => $product->regular_price, 
'description' => $product->description,
'categories' => array(
    array( 
        'id' => 343
    ),
    array(
        'id' => 347
    )
)
));
正如我所说,其他字段按预期更新。我已经确认ID为343和347的类别肯定存在,所以我想我一定有语法问题。随着其他字段的更新,身份验证肯定会起作用

我已经阅读了官方的WooCommerceAPI文档,并根据教程编写了代码。基于这两方面,我不确定我做错了什么


谢谢你的帮助和建议。

我最终解决了这个问题。这是我的疏忽

我使用的客户端库连接到Woocommerce文档所称的“Legacy v2”版本,而不是API的“v2”版本。旧版本中不支持类别、图像alt标记、元数据等

我从使用库切换到使用直接连接到“v2”版本,现在一切正常