使用C#中的WooCommerce.NET/Rest API更新产品属性

问题描述

我在C#中使用WooCommerce Rest API 我在用C#在WooCommerce中添加具有(Attribute / Variant / Image / Category)的产品没有问题

我使用以下代码获取产品代码,并且可以添加(Attribute / Variant / Image / Category)

RestAPI rest = new RestAPI("https://examople.com/wp-json/wc/v3","ck_021ac*************5d20249","cs_24c387************659ee3d588cf",false);
        WCObject wc = new WCObject(rest);

        string SKU = "2222";
        List<Product> products = new List<Product>();
        Dictionary<string,string> pDic = new Dictionary<string,string>();
        pDic.Add("sku",SKU);

        int productIDfromSKU = 0;
        //int productNfromSKU = 0;
        products = await wc.Product.GetAll(pDic);

        if (products.Count > 0)
        {
            productIDfromSKU = Convert.ToInt32(products[0].id);
            //productNfromSKU = Convert.ToInt32(products[0].price);
        }
        MessageBox.Show(productIDfromSKU.ToString());

但是对于更新(属性/变量/图像/类别),任何地方都没有代码或示例

解决方法

对于变体更新:我试过了,这是有效的。

Variation v = new Variation()
              {
                  id = 25501
                  stock_status = "outofstock"
              };

var res = await wc.Product.Variations.Update(25496,v,25496); // set productid as parent id

与属性/图像/类别更新相同。

我仍在寻找为产品指定品牌。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...