SDKs overview

WooCommerce offers several Software Development Kits (SDKs) and libraries designed to facilitate interaction with its e-commerce platform. These tools streamline the process of integrating external applications, building custom functionalities, and automating store management tasks. The primary method of interaction for external applications is through the WooCommerce REST API, which allows programmatic access to store data such as products, orders, customers, and reports WooCommerce REST API documentation. SDKs abstract the complexities of HTTP requests, authentication, and response parsing, enabling developers to focus on application logic rather than API mechanics.

For WordPress plugin and theme developers, WooCommerce also exposes a rich set of hooks and filters, which are fundamental to extending its core functionality directly within the WordPress environment. While not strictly 'SDKs' in the traditional sense, these programmatic interfaces are crucial for deep customization and are extensively documented WooCommerce developer resources. This page focuses on libraries for external application development, primarily those interacting with the REST API.

Official SDKs by language

WooCommerce maintains official SDKs primarily for PHP, reflecting its WordPress foundation. These official libraries are developed and supported by Automattic, the company behind WooCommerce, ensuring compatibility and adherence to best practices. They provide a structured way to interact with the WooCommerce REST API from various application environments.

Language Package Name Description Maturity Documentation
PHP automattic/woocommerce-rest-api-php-wrapper Official PHP client for the WooCommerce REST API, simplifying API calls and authentication. Stable PHP Wrapper GitHub repository

The official PHP wrapper provides methods for common API operations such as retrieving product lists, creating new orders, updating customer details, and managing coupons. It handles OAuth 1.0a signature generation, which is the recommended authentication method for WooCommerce REST API requests WooCommerce REST API authentication guide. Developers can install it via Composer, the dependency manager for PHP.

Installation

Installation instructions vary by language and package manager. For the official PHP SDK, Composer is the standard method. Ensure you have Composer installed on your development environment before proceeding.

PHP SDK Installation

To install the official WooCommerce REST API PHP Client, navigate to your project directory in the terminal and execute the following Composer command:


composer require automattic/woocommerce-rest-api-php-wrapper

This command downloads the library and its dependencies, adding them to your project's vendor/ directory and updating your composer.json and composer.lock files. After installation, you can include the Composer autoloader in your PHP script to make the library classes available:


require __DIR__ . '/vendor/autoload.php';

Other Language Installations (Community)

For community-maintained libraries in other languages, installation typically follows the conventions of their respective ecosystems. For instance, Python libraries are often installed via pip, JavaScript libraries via npm or yarn, and Ruby gems via gem install. Developers should consult the specific library's documentation for precise installation instructions.

Quickstart example

This example demonstrates how to use the official PHP SDK to fetch a list of products from a WooCommerce store. Before running this code, ensure you have installed the PHP SDK as described above and generated API keys (Consumer Key and Consumer Secret) from your WooCommerce store's settings under WooCommerce > Settings > Advanced > REST API WooCommerce API key generation.


<?php

require __DIR__ . '/vendor/autoload.php';

use Automattic\WooCommerce\Client;

// Replace with your actual store URL and API keys
$store_url = 'https://your-woocommerce-store.com';
$consumer_key = 'ck_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$consumer_secret = 'cs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

$woocommerce = new Client(
    $store_url,
    $consumer_key,
    $consumer_secret,
    [
        'version' => 'wc/v3',
        'verify_ssl' => true, // Set to false for development with self-signed SSL
        'timeout' => 30,
    ]
);

try {
    // Fetch products
    $products = $woocommerce->get('products');

    echo "<h2>Products:</h2>";
    if (!empty($products)) {
        echo "<ul>";
        foreach ($products as $product) {
            echo "<li>" . htmlspecialchars($product->name) . " (ID: " . htmlspecialchars($product->id) . ")</li>";
        }
        echo "</ul>";
    } else {
        echo "<p>No products found.</p>";
    }

    // Example: Fetch a specific product by ID (replace 123 with an actual product ID)
    // $singleProduct = $woocommerce->get('products/123');
    // echo "<h3>Single Product:</h3>";
    // print_r($singleProduct);

} catch (Exception $e) {
    echo "Error: " . htmlspecialchars($e->getMessage());
    if (method_exists($e, 'getResponse')) {
        echo "<br>Response: " . htmlspecialchars($e->getResponse());
    }
}

?>

This script initializes the WooCommerce client with your store's URL and API credentials, then uses the get('products') method to retrieve product data. The results are then iterated and displayed. Error handling is included to catch potential issues during API communication.

Community libraries

Beyond the official PHP SDK, the WooCommerce ecosystem benefits from a variety of community-contributed libraries across different programming languages. These libraries often provide similar functionality to the official SDKs, enabling developers to interact with the WooCommerce REST API using their preferred language. While not officially supported by Automattic, many of these libraries are actively maintained by their respective communities and offer robust solutions for integration.

Python

  • WooCommerce REST API Client for Python: This popular library allows Python developers to easily make API calls to WooCommerce. It supports various authentication methods and provides a Pythonic interface for managing store resources. Installation is typically via pip install woocommerce. Developers can find more details and usage examples on its WooCommerce Python Client GitHub page.

JavaScript / Node.js

  • WooCommerce REST API Client for JavaScript: Designed for Node.js environments and potentially browser-side applications (with appropriate CORS configuration), this library simplifies interaction with the WooCommerce API using JavaScript. It handles request signing and response parsing. It can be installed via npm install @woocommerce/woocommerce-rest-api. For detailed usage, refer to the JavaScript API Wrapper documentation.

Ruby

  • WooCommerce API for Ruby: A gem providing a Ruby interface for the WooCommerce REST API. It supports common operations and is suitable for Ruby on Rails applications or other Ruby-based projects. Installation is typically via gem install woocommerce_api. Further information is available on its Ruby API client GitHub repository.

Other Languages

Community efforts extend to other languages such as Java, C#, and Go, with various open-source projects available on platforms like GitHub. Developers seeking libraries in these languages should search the respective package repositories or GitHub for projects tagged with 'woocommerce' or 'wc-api'. When choosing a community library, it is advisable to check its maintenance status, community activity, and compatibility with the latest WooCommerce REST API version. Consulting the Mozilla HTTP status codes reference can also be helpful for understanding API responses when working with any client library.