XiaoFaye / WooCommerce.NET

A .NET Wrapper for WooCommerce/WordPress REST API
MIT License
391 stars 217 forks source link
api-client c-sharp restful-api woocommerce wordpress-api wordpress-plugin

WooCommerce.NET

A Brief Intro

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

NuGet

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 (me:sunglasses:), thank you!

Usage (WooCommerce REST API)

Click to expand/collapse details... ```cs using WooCommerceNET.WooCommerce.v3; using WooCommerceNET.WooCommerce.v3.Extension; RestAPI rest = new RestAPI("http://www.yourstore.co.nz/wp-json/wc/v3/", "", "() { { "include", "10, 11, 12, 13, 14, 15" }, { "per_page", "15" } }); //Batch add/update/delete CustomerBatch cb = new CustomerBatch(); List create = new List(); create.Add(new Customer() { first_name = "first", last_name = "last", email = "first@lastsss.com", username = "firstnlast", password = "12345" }); List update = new List(); update.Add(new Customer() { id = 4, last_name = "xu2" }); List delete = new List() { 8 }; cb.create = create; cb.update = update; cb.delete = delete; var c = await wc.Customer.UpdateRange(cb); ```

Usage (WordPress REST API - JWT/OAuth Authentication)

Click to expand/collapse details... ```cs //using JWT RestAPI rest = new RestAPI("http://www.yourstore.co.nz/wp-json/jwt-auth/v1/token", "", ""); //using OAuth RestAPI rest = new RestAPI("http://www.yourstore.co.nz/wp-json/wp/v2/", "", ""); rest.oauth_token = ""; rest.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 = "

abc

" }; 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 = "test123@gmail.com", password = "test@12345" }); ```