WooCommerce API creates images in media even if they exist

你。 提交于 2019-12-11 04:46:42

问题


What might be a reason? Trying to batch update product images (and price) in WooCommerce via REST API. Images already exist in wordpress media library and links are correctly copied. However, instead of using image it creates new image.

Request: POST. URL: https://SiteURL/wp-json/wc/v2/products/xxxx?consumer_key=c______&consumer_secret=_____

Body:

 {"update":[
      {"regular_price":"448",
         "images":[
             {"src":"https://urlToImage.jpg",
               "position":0, "name": "test"}
      ],"id":"xxxx"}]}

In response I can see it creates image with the same url but as there is already an image in the library, it adds -1 to url.

Thank you in forward :)


回答1:


Since this is an update where the images already exists you need to set the id member of the images element. Otherwise, WooCommerce interprets this as a request to add a new image to the product gallery.



来源:https://stackoverflow.com/questions/49640046/woocommerce-api-creates-images-in-media-even-if-they-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!