如何解决使用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
与属性/图像/类别更新相同。
我仍在寻找为产品指定品牌。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。