Laravel 5 WooCommerce API Client
A simple Laravel 5 wrapper for the official WooCommerce REST API PHP Library from Automattic.
Installation
Step 1: Install Through Composer
composer require pixelpeter/laravel5-woocommerce-api-client
Step 2: Add the Service Provider
Add the service provider in app/config/app.php
'provider' => [
...
Pixelpeter\Woocommerce\WoocommerceServiceProvider::class,
...
];
Step 3: Add the Facade
Add the alias in app/config/app.php
'aliases' => [
...
'Woocommerce' => Pixelpeter\Woocommerce\Facades\Woocommerce::class,
...
];
Step 4: Customize configuration
You can directly edit the configuration in config/woocommerce.php
or copy these values to your .env
file.
WOOCOMMERCE_STORE_URL=http://example.org
WOOCOMMERCE_CONSUMER_KEY=ck_your-consumer-key
WOOCOMMERCE_CONSUMER_SECRET=cs_your-consumer-secret
WOOCOMMERCE_VERIFY_SSL=false
WOOCOMMERCE_VERSION=v3
Examples
Get the index of all available endpoints
use Woocommerce;
return Woocommerce::get('');
View all orders
use Woocommerce;
return Woocommerce::get('orders');
View all completed orders created after a specific date
use Woocommerce;
$data = [
'status' => 'completed',
'filter' => [
'created_at_min' => '2016-01-14'
]
];
$result = Woocommerce::get('orders', $data);
foreach($result['orders'] as $order)
{
// do something with $order
}
// you can also use array access
$orders = Woocommerce::get('orders', $data)['orders'];
foreach($orders as $order)
{
// do something with $order
}
Update a product
use Woocommerce;
$data = [
'product' => [
'title' => 'Updated title'
]
];
return Woocommerce::put('products/1', $data);
More Examples
Refer to WooCommerce REST API Documentation for more examples and documention.
Testing
Run the tests with:
vendor/bin/phpunit
License
The MIT License (MIT). Please see License File for more information.