【问题标题】:Woocommerce Rest API issue with stock quantity库存数量的 Woocommerce Rest API 问题
【发布时间】:2018-08-23 13:01:45
【问题描述】:

我在我的 ionic 应用中创建 Woocommerce 产品。我还想在创建产品时推送库存数量。但是,库存始终是 NULL 存储在我的 MYSQL 数据库中。这是 JSON 提要

{
  "product": {
    "title": "test stock",
    "stock_quantity": "35",
    "images": [],
    "post_author": 88,
    "type": "simple",
    "categories": []
  }
}: 

这里是应用程序中的一段代码

  var productInfo = {
    title: this.productName,
    regular_price: this.productPrice,
    sale_price: this.productDiscount,
    stock_quantity: this.productStock,
    description: this.productDesc,
    images: new Array<any>(),
    post_author: this.userService.id,
    type: this.productType,
    categories: new Array<any>()
  };

我为 stock_quantity 尝试了不同的标签,比如只有“stock”,并尝试用“”推送变量,而没有它。但我仍然面临同样的问题。

【问题讨论】:

    标签: php woocommerce


    【解决方案1】:

    您的 JSON 语法是正确的。此外,您将正确的股票参数传递为stock_quantity,并且当我查看您的 JSON 请求时,您没有将 manage_stock 参数传递为默认情况下认为为 false 的 true。因此,您还需要传递该参数。

    你可以试试下面的代码。

    {
     "product": {
     "title": "test stock",
     "stock_quantity": "35",
     "manage_stock": true,
     "images": [],
     "post_author": 88,
     "type": "simple",
     "categories": []
     }
    }: 
    

    您可以参考 WooCommerce REST API Product Properties for create products

    【讨论】:

    • 我也这样做了,但我仍然得到响应为空。
    猜你喜欢
    • 2020-12-24
    • 2020-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-05
    • 2017-11-19
    相关资源
    最近更新 更多