Giter Site home page Giter Site logo

woocommerce-go's Introduction

WooCommerce SDK for golang

Docs

Rest API Docs

https://woocommerce.github.io/woocommerce-rest-api-docs/#introduction

Requirements

To use the latest version of the REST API you must be using:

  • WooCommerce 3.5+.
  • WordPress 4.4+.

Pretty permalinks in Settings > Permalinks so that the custom endpoints are supported. Default permalinks will not work. You may access the API over either HTTP or HTTPS, but HTTPS is recommended where possible. If you use ModSecurity and see 501 Method Not Implemented errors, see this issue for details.

Notices

Only tested in API v3, if you are use v1 or v2, please Report an issue.

Install

go get github.com/hiscaler/woocommerce-go

Config

{
  "debug": true,
  "url": "http://127.0.0.1/",
  "version": "v3",
  "consumer_key": "",
  "consumer_secret": "",
  "add_authentication_to_url": false,
  "timeout": 10,
  "verify_ssl": true
}

Usage

Step 1. Create a new client

// Read you config
b, err := os.ReadFile("./config/config_test.json")
if err != nil {
    panic(fmt.Sprintf("Read config error: %s", err.Error()))
}
var c config.Config
err = json.Unmarshal(b, &c)
if err != nil {
    panic(fmt.Sprintf("Parse config file error: %s", err.Error()))
}

wooClient := NewClient(c)

Now you get a wooCommerce client object, If you want to operate data, please refer second step.

Step 2. Call special service method

// Product Query
params := ProductsQueryParams{}
wooClient.Services.Product.All(params)

10 records are returned by default.

In most cases, you can filter by condition, example:

params.SKU = "NO123"
wooClient.Services.Product.All(params)

The first ten eligible records are returned in this case

And you can retrieve one data use One() method.

product, err := wooClient.Services.Product.One(1)

Note: If the error type is ErrNotFound, it indicates that the corresponding data is not found. If the error type is other error, an error may occur in the call. So you should judge the results to further process your business logic.

Services

Service method name description:

Method Name Description
Create() Create a new data
All() Get a data list
One() Get one data
Delete() Delete a data
Update() Update a data
Batch() Batch operate data

Coupons

Service Name: wooClient.Service.Coupon

Methods:

  • All
  • Batch
  • Create
  • Delete
  • One
  • Update

Customers

Service Name: wooClient.Service.Customer

Methods:

  • All
  • Batch
  • Create
  • Delete
  • Downloads
  • One
  • Update

Order

Service Name: wooClient.Service.Order

Methods:

  • All
  • Create
  • Delete
  • One
  • Update

Order Notes

Service Name: wooClient.Service.OrderNote

Methods:

  • All
  • Create
  • Delete
  • One

Refunds

Service Name: wooClient.Service.OrderRefund

Methods:

  • All
  • Create
  • Delete
  • One

Products

Service Name: wooClient.Service.Product

Methods:

  • All
  • Create
  • Delete
  • One
  • Update

Product Variations

Service Name: wooClient.Service.ProductVariation

Methods:

  • All
  • Batch
  • Create
  • Delete
  • One
  • Update

Product Attributes

Service Name: wooClient.Service.ProductAttribute

Methods:

  • All
  • Batch
  • Create
  • Delete
  • One
  • Update

Product Attribute Terms

Service Name: wooClient.Service.ProductAttributeTerm

Methods:

  • All
  • Batch
  • Create
  • Delete
  • One
  • Update

Product Categories

Service Name: wooClient.Service.ProductCategory

Methods:

  • All
  • Batch
  • Create
  • Delete
  • One
  • Update

Product Shipping Classes

Service Name: wooClient.Service.ProductShippingClass

Methods:

  • All
  • Batch
  • Create
  • Delete
  • One
  • Update

Product Tags

Service Name: wooClient.Service.ProductTag

Methods:

  • All
  • Batch
  • Create
  • Delete
  • One
  • Update

Product Reviews

Service Name: wooClient.Service.ProductReview

Methods:

  • All
  • Batch
  • Create
  • Delete
  • One
  • Update

Report

Service Name: wooClient.Service.Report

Methods:

  • All
  • CouponTotals
  • CustomerTotals
  • OrderTotals
  • ProductTotals
  • ReviewTotals
  • SalesReports
  • TopSellerReports

Tax Rates

Service Name: wooClient.Service.TaxRate

Methods:

  • All
  • Batch
  • Create
  • Delete
  • One
  • Update

Tax Classes

Service Name: wooClient.Service.TaxClass

Methods:

  • All
  • Create
  • Delete

Webhooks

Service Name: wooClient.Service.Webhook

Methods:

  • All
  • Batch
  • Create
  • Delete
  • One
  • Update

Settings

  • Groups

Service Name: wooClient.Service.Group

Methods:

Setting Options

  • All
  • One
  • Update

Payment Gateways

Service Name: wooClient.Service.PaymentGateway

Methods:

  • All
  • One
  • Update

Shipping Zones

Service Name: wooClient.Service.ShippingZone

Methods:

  • All
  • Create
  • Delete
  • One
  • Update

Shipping Zone Locations

Service Name: wooClient.Service.ShippingZoneLocation

Methods:

  • All
  • Update

Shipping Zone Methods

Service Name: wooClient.Service.ShippingZoneMethod

Methods:

  • All
  • Delete
  • Include
  • One
  • Update

Shipping Methods

Service Name: wooClient.Service.ShippingMethod

Methods:

  • All
  • One

System Status

Service Name: wooClient.Service.SystemStatus

Methods:

  • All

System Status Tools

Service Name: wooClient.Service.SystemStatusTool

Methods:

  • All
  • One
  • Run

Data

Service Name: wooClient.Service.Data

Methods:

  • All
  • Continent
  • Continents
  • Countries
  • Country
  • Currencies
  • Currency
  • CurrentCurrency

Contributing

If you have any questions or suggestions, you can:

  1. Report an issue
  2. Fork it and pull a request

Thanks.

woocommerce-go's People

Contributors

hiscaler avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.