WooCommerce.NET

XiaoFayeMIT更新放缓

用 C# 封装 WooCommerce/WordPress REST API 的 .NET 客户端库,让 .NET 开发者无需手写 HTTP 请求就能调用商品、订单等接口。

A .NET Wrapper for WooCommerce/WordPress REST API

0.8.7发布于 2026-04-22 00:58 UTC413star225fork同步于 2026-11-07 07:32 UTC

怎么上手

由 README 提炼,执行前请确认
dotnet add package WooCommerceNET
硬件要求按 README 说明

README 未说明

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用 C# 调用 WooCommerce 和 WordPress REST API 的 .NET 封装库,省去手写 HTTP 请求和认证

用 C# 封装 WooCommerce/WordPress REST API 的 .NET 客户端库,让 .NET 开发者无需手写 HTTP 请求就能调用商品、订单等接口。

核心能力

  • 封装 WooCommerce v3 的 Product、Customer 等对象增删改查
  • 支持批量 create/update/delete 的 Batch 接口
  • 支持 WordPress REST API 的 JWT 与 OAuth 1.0a 认证
  • 提供 webRequestFilter/webResponseFilter 请求响应钩子
  • 可指定 CultureInfo 处理不同区域格式

容易踩的坑

需先在 WordPress 端安装并配置 JWT 或 OAuth 插件才能用 WordPress API;调用前要准备好 WooCommerce Key/Secret 或 OAuth Token;DELETE/PUT 在部分环境需启用 X-HTTP-Method-Override 头

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本0.8.7
  1. 0.8.7Version 0.8.7最新正式版2026-04-22 · 2026-04-22 00:58 UTC
    1. Allow authorized with Application Passwords for WordPress.
    2. Add support for Brands. #795
    3. Add Variation GTIN, UPC, EAN o ISBN field.
    4. Update data type from integer to unsigned long for more fields.
  2. 0.8.6Version 0.8.62023-03-29 · 2023-03-29 01:20 UTC
    查看更新说明
    • v0.8.6 update
      1. Fix manage_stock property deserializing issue in Project object. #722
      2. Add Culture object in WCObject constructor to resolve format issue. #731
      3. Allow accessing WordPress plugin REST API with WooCommerce secret and key.
  3. 0.8.5Version 0.8.52023-01-04 · 2023-01-04 03:16 UTC
    查看更新说明

    Version 0.8.5

  4. 0.8.4Version 0.8.42021-11-20 · 2021-11-20 01:41 UTC
    查看更新说明
    1. Change all id field to 64bit integer (unsigned long) to prevent overflow. #560
    2. Create RestClient.cs to use HttpClient, as Blazor does not support HttpWebRequest. PR#639
    3. Accept '&' in password while calling WordPress Restful API. PR#527
    4. Close HttpWebRequest write stream when finish. PR#529
    5. Add WCObject.MetaDisplayValueProcessor function. PR#600
    6. Add OrderCouponLineMeta class. PR#600
    7. Change MetaData.display_value field to type object and run it through MetaDisplayValueProcessor() if configured. PR#600
  5. 0.8.3Version 0.8.32021-03-17 · 2021-03-17 08:19 UTC
    查看更新说明
    1. Fix error while creating a refund. #476
    2. Allow authenticate Woocommerce API with JWT (set WCAuthWithJWT to true). #478
    3. Fix error on retrieving refund. #484
    4. Fix error on deserialize BatchObject. #523
    5. Fix error on date format. #524
    6. Add user-friendly attribute names and values to Metadata. #558
    7. Change all id field to unsigned 32bit integer to prevent overflow. #560
    8. Change functions in BaseObject to virtual to support Unit Test. #568
    9. Add function to delete tax class by slug. #576
    10. Allow WC Plugins to use WCObject.
    11. Add UpdateRangeRaw to ignore deserialize return json. #523

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    WooCommerce.NET

    A Brief Intro

    WooCommerce.NET is a .NET library for calling WooCommerce/WordPress REST API with OAuth/JWT in .NET applications.

    NuGet stable version

    If this project has been helpful for you and you want to support it, please consider Buying me a coffee:coffee:

    For priority paid support/consulting service, customized REST API development and plugins REST API development, please email to James, thank you!

    Usage (WooCommerce REST API)

    using WooCommerceNET.WooCommerce.v3;
    using WooCommerceNET.WooCommerce.v3.Extension;
    
    RestAPI rest = new RestAPI("http://www.yourstore.co.nz/wp-json/wc/v3/", "<WooCommerce Key>", "<WooCommerce Secret");
    WCObject wc = new WCObject(rest);
    
    //Use below code for WCObject only if you would like to have different CultureInfo
    WCObject wc = new WCObject(rest, CultureInfo.GetCultureInfo("de-DE"));
    
    //Get all products
    var products = await wc.Product.GetAll();
    
    //Add new product
    Product p = new Product()
                {
                    name = "test product 8",
                    title = "test product 8",
                    description = "test product 8",
                    price = 8.0M
                };
    await wc.Product.Add(p);
    
    //Update products with new values
    await wc.Product.Update(128, new Product { name = "test 9" });
    
    //Update products with Null values
    await wc.Product.UpdateWithNull(128, new { name = "test 9", weight = "", date_on_sale_from = "", date_on_sale_to = "" });
    
    //Delete product
    await wc.Product.Delete(128);
    
    //Use parameters
    var p = await wc.Product.GetAll(new Dictionary<string, string>() {
                    { "include", "10, 11, 12, 13, 14, 15" },
                    { "per_page", "15" } });
    
    
    //Batch add/update/delete
    CustomerBatch cb = new CustomerBatch();
    
    List<Customer> create = new List<Customer>();
    create.Add(new Customer()
    {
        first_name = "first",
        last_name = "last",
        email = "[email protected]",
        username = "firstnlast",
        password = "12345"
    });
    
    List<Customer> update = new List<Customer>();
    update.Add(new Customer()
    {
        id = 4,
        last_name = "xu2"
    });
    
    List<int> delete = new List<int>() { 8 };
    cb.create = create;
    cb.update = update;
    cb.delete = delete;
    
    var c = await wc.Customer.UpdateRange(cb);
    
    

    Usage (WordPress REST API - JWT/OAuth Authentication)

    
    //using JWT
    RestAPI rest = new RestAPI("http://www.yourstore.co.nz/wp-json/jwt-auth/v1/token", "<UserName>", "<Password>");
    
    //using OAuth
    RestAPI rest = new RestAPI("http://www.yourstore.co.nz/wp-json/wp/v2/", "<Client_Key>", "<Client_Secret>");
    rest.oauth_token = "<OAuth_Token>";
    rest.oauth_token_secret = "<OAuth_Token_Secret>";
    
    WPObject wp = new WPObject(rest);
    
    //Get all posts
    var posts = await wp.Post.GetAll();
    
    //Add a post
    var p = new Posts()
    {
        title = "abc",
        content = "<h1>abc</h1>"
    };
    
    await wp.Post.Add(p);
    
    //Update post with new values
    await wp.Post.Update(123, new { title = "new post" });
    
    //Delete a post
    await wp.Post.Delete(123);
    
    //Upload an image
    await wp.Media.Add("imagename.jpg", @"C:\path\to\image\file.jpg");
    
    //Create a new user
    await wp.Users.Add(new Users()
    {
        first_name = "test",
        last_name = "test",
        name = "test",
        username = "test123",
        email = "[email protected]",
        password = "test@12345"
    });