WooCommerce API 在媒体中创建图像,即使它们存在

Arū*_*šis 3 woocommerce woocommerce-rest-api

可能是什么原因?尝试通过 REST API 在 WooCommerce 中批量更新产品图像(和价格)。图片已存在于 wordpress 媒体库中,链接已正确复制。但是,它不是使用图像而是创建新图像。

请求:POST。网址:https://SiteURL/wp-json/wc/v2/products/xxxx?consumer_key=c______&consumer_secret=_____

身体:

 {"update":[
      {"regular_price":"448",
         "images":[
             {"src":"https://urlToImage.jpg",
               "position":0, "name": "test"}
      ],"id":"xxxx"}]}
Run Code Online (Sandbox Code Playgroud)

作为回应,我可以看到它创建了具有相同 url 的图像,但由于库中已经有一个图像,它将 -1 添加到 url。

谢谢你的转发:)

小智 6

由于这是图像已经存在的更新,因此您需要设置图像元素的 id 成员。否则,WooCommerce 会将其解释为向产品库添加新图像的请求。