在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):pixelpeter/laravel5-woocommerce-api-client开源软件地址(OpenSource Url):https://github.com/pixelpeter/laravel5-woocommerce-api-client开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Laravel 5 WooCommerce API ClientA simple Laravel 5 wrapper for the official WooCommerce REST API PHP Library from Automattic. Version overview
InstallationStep 1: Install Through ComposerFor API Version v2, WooCommerce 3.0+, Wordpress 4.4+, php 7.0+, Laravel 5.5+ use the v3.x branch composer require pixelpeter/laravel5-woocommerce-api-client ^3.0 For API Version v1, WooCommerce 2.6+, Wordpress 4.4+, Laravel 5.4+ use the v2.x branch composer require pixelpeter/laravel5-woocommerce-api-client ^2.0 For older versions of Woocommerce starting from 2.1+ use the v1.x branch composer require pixelpeter/laravel5-woocommerce-api-client ^1.0 Step 2: Add the Service Provider (not needed with v3.x)Add the service provider in 'provider' => [
...
Pixelpeter\Woocommerce\WoocommerceServiceProvider::class,
...
]; Step 3: Add the Facade (not needed with v3.x)Add the alias in 'aliases' => [
...
'Woocommerce' => Pixelpeter\Woocommerce\Facades\Woocommerce::class,
...
]; Step 4: Publish configurationphp artisan vendor:publish --provider="Pixelpeter\Woocommerce\WoocommerceServiceProvider" Step 5: Customize configurationYou can directly edit the configuration in 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=v1
WOOCOMMERCE_WP_API=true
WOOCOMMERCE_WP_QUERY_STRING_AUTH=false
WOOCOMMERCE_WP_TIMEOUT=15 ExamplesGet the index of all available endpointsuse Woocommerce;
return Woocommerce::get(''); View all ordersuse Woocommerce;
return Woocommerce::get('orders'); View all completed orders created after a specific dateFor legacy API versions(WC 2.4.x or later, WP 4.1 or later) use this syntax 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
} For current API versions(WC 2.6.x or later, WP 4.4 or later) use this syntax.
use Woocommerce;
$data = [
'status' => 'completed',
'after' => '2016-01-14T00:00:00'
]
];
$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 productuse Woocommerce;
$data = [
'product' => [
'title' => 'Updated title'
]
];
return Woocommerce::put('products/1', $data); PaginationSo you don't have to mess around with the request and response header and the calculations this wrapper will do all the heavy lifting for you. (WC 2.6.x or later, WP 4.4 or later) use Woocommerce;
// assuming we have 474 orders in pur result
// we will request page 5 with 25 results per page
$params = [
'per_page' => 25,
'page' => 5
];
Woocommerce::get('orders', $params);
Woocommerce::totalResults(); // 474
Woocommerce::firstPage(); // 1
Woocommerce::lastPage(); // 19
Woocommerce::currentPage(); // 5
Woocommerce::totalPages(); // 19
Woocommerce::previousPage(); // 4
Woocommerce::nextPage(); // 6
Woocommerce::hasPreviousPage(); // true
Woocommerce::hasNextPage(); // true
Woocommerce::hasNotPreviousPage(); // false
Woocommerce::hasNotNextPage(); // false HTTP Request & Response (Headers)use Woocommerce;
// first send a request
Woocommerce::get('orders');
// get the request
Woocommerce::getRequest();
// get the response headers
Woocommerce::getResponse();
// get the total number of results
Woocommerce::getResponse()->getHeaders()['X-WP-Total'] More ExamplesRefer to WooCommerce REST API Documentation for more examples and documention. TestingRun the tests with: vendor/bin/phpunit LicenseThe MIT License (MIT). Please see License File for more information. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论