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

WooCommerce API creates images in media even if they exist

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

请求:POST。 URL: 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"}]}

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

谢谢转发:)

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